Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 48789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:20:06+00:00 2026-05-10T16:20:06+00:00

I’m processing a huge file with (GNU) awk , (other available tools are: Linux

  • 0

I’m processing a huge file with (GNU) awk, (other available tools are: Linux shell tools, some old (>5.0) version of Perl, but can’t install modules).

My problem: if some field1, field2, field3 contain X, Y, Z I must search for a file in another directory which contains field4, and field5 on one line, and insert some data from the found file to the current output.

E.g.:

Actual file line:

f1 f2 f3 f4 f5 X  Y  Z  A  B 

Now I need to search for another file (in another directory), which contains e.g.

f1 f2 f3 f4 A  U  B  W 

And write to STDOUT $0 from the original file, and f2 and f3 from the found file, then process the next line of the original file.

Is it possible to do it with awk?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T16:20:07+00:00Added an answer on May 10, 2026 at 4:20 pm

    Let me start out by saying that your problem description isn’t really that helpful. Next time, please just be more specific: You might be missing out on much better solutions.

    So from your description, I understand you have two files which contain whitespace-separated data. In the first file, you want to match the first three columns against some search pattern. If found, you want to find all lines in another file which contain the fourth and and fifth column of the matching line in the first file. From those lines, you need to extract the second and third column and then print the first column of the first file and the second and third from the second file. Okay, here goes:

    #!/usr/bin/env perl -nwa use strict; use File::Find 'find'; my @search = qw(X Y Z);  # if you know in advance that the otherfile isn't # huge, you can cache it in memory as an optimization.  # with any more columns, you want a loop here: if ($F[0] eq $search[0]     and $F[1] eq $search[1]     and $F[2] eq $search[2]) {   my @files;   find(sub {       return if not -f $_;       # verbatim search for the columns in the file name.       # I'm still not sure what your file-search criteria are, though.       push @files, $File::Find::name if /\Q$F[3]\E/ and /\Q$F[4]\E/;       # alternatively search for the combination:       #push @files, $File::Find::name if /\Q$F[3]\E.*\Q$F[4]\E/;       # or search *all* files in the search path?       #push @files, $File::Find::name;     }, '/search/path'   )   foreach my $file (@files) {     open my $fh, '<', $file or die 'Can't open file '$file': $!';     while (defined($_ = <$fh>)) {       chomp;       # order of fields doesn't matter per your requirement.       my @cols = split ' ', $_;       my %seen = map {($_=>1)} @cols;       if ($seen{$F[3]} and $seen{$F[4]}) {         print join(' ', $F[0], @cols[1,2]), '\n';       }     }     close $fh;   } } # end if matching line 

    Unlike another poster’s solution which contains lots of system calls, this doesn’t fall back to the shell at all and thus should be plenty fast.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 95k
  • Answers 95k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use TEXT =CONCATENATE(A1," ",TEXT(B1,"dd mmm yyyy")," - ",TEXT(C1,"dd/mm/yyyy")) May 11, 2026 at 7:01 pm
  • Editorial Team
    Editorial Team added an answer I don't think its necessarily bad practice. There are a… May 11, 2026 at 7:01 pm
  • Editorial Team
    Editorial Team added an answer What you are asking for is not possible. Can you… May 11, 2026 at 7:01 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.