Match Fields between two files, print portions of each file together when matched in ([g]awk)'


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Match Fields between two files, print portions of each file together when matched in ([g]awk)'
# 1  
Old 01-04-2018
Match Fields between two files, print portions of each file together when matched in ([g]awk)'

I've written an awk script to compare two fields in two different files and then print portions of each file on the same line when matched. It works reasonably well, but every now and again, I notice some errors and cannot seem to figure out what the issue may be and am turning to you for help.

My ultimate goal is to do this: If $1 and $2 of file2 match $1 and $2 of file1 I would like to print $1, $2, and $3 of file2 followed by fields $3 through $23 (making them $4 through $24 in the output) of file1 on the same line. Else, if $2 of file2 has a "?", then I would like to print $1, $2, and $3 of file2 followed by "-" in $4-$24 of the output. My two input files look like this:

File1
Code:
PS009,001 L                   0   5 -1 -1 -1 -1 -1   -1 -1 -1 -1    -1   5   0  -1      -1      -1      -1   -1   -1    -1
PS009,001 H                   0   0 -1 -1 -1 -1 -1   -1 -1 -1 -1    -1   0   0  -1      -1      -1      -1   -1   -1    -1
PS009,001 NYX                 0   1  7  1  1  1 -1    6  0  1  2     2   2   5   2      -1      -1      -1    0  521     0
           * 0 1 100 2 100 0 0 .N 0 LineNr 1 ClauseNr 1: 1: 1: 200: 0 0 SentenceNr 1 TxtType: ? Pargr: 1 ClType:NmCl
PS009,001 <LMWT               0   2 -1 -1 -1  1 -1   -1 -1  1  1     2   2   2   1      -1      -1      -1    0  521     0
PS009,001 L                   0   5 -1 -1 -1 -1 -1   -1 -1 -1 -1    -1   5   0  -1      -1      -1      -1   -1   -1    -1
PS009,001 H                   0   0 -1 -1 -1 -1 -1   -1 -1 -1 -1    -1   0   0  -1      -1      -1      -1   -1   -1    -1
PS009,001 BN                  0   2 -1 -1 -1  1 -1   -1 -1  1  2     2   2   5   2      -1      -1      -1  -11  582     0
           * 0 -1 100 0 0 .. 2 LineNr 2 ClauseNr 1: 1: 1: 200: 0 0 SentenceNr 2 TxtType: ? Pargr: 1 ClType:NmCl
PS009,001 MZMWR               0   2 -1 -1 -1  1 -1   -1 -1  1  2     2   2   2   1      -1      -1      -1    0  521     0
PS009,001 L                   0   5 -1 -1 -1 -1 -1   -1 -1 -1 -1    -1   5   0  -1      -1      -1      -1   -1   -1    -1
PS009,001 DWD                 0   3 -1 -1 -1  1 -1   -1 -1  1  2     2   3   5   2      -1      -1      -1  -11  582     0
           * 0 -2 100 0 0 .. 1 LineNr 3 ClauseNr 1: 1: 1: 200: 0 0 SentenceNr 3 TxtType: ? Pargr: 1 ClType:NmCl
PS009,002 JDH                 0   1  4  2  1 -1 -1    1  1  1  0    -1   1   1  -1      -1      -1      -1    0  501     0
PS009,002 JHWH                0   3 -1 -1 -1  1 -1   -1 -1  1  2     2   3   3   2      -1      -1      -1    0  503     0
PS009,002 B                   0   5 -1 -1 -1 -1 -1   -1 -1 -1 -1    -1   5   0  -1      -1      -1      -1   -1   -1    -1
PS009,002 KL                 -6   2 -1 -1 -1  1 -1   -1 -1  1  2     1   2   0  -1       2      -1      -1   -1   -1    -1
PS009,002 LB                  0   2 -1 -1 -1  1 -1   -1 -1  1  2     1   2   0  -1      -1      -1      -1   -1   -1    -1
PS009,002 J                  -1   7 -1 -1 -1 -1 -1   -1  1  1 -1    -1   7   5   2  -20102      -1      -1    0  505     0
           * 0 1 200 18 411 27 131 33 131 0 0 .N 0 LineNr 4 ClauseNr 1: 1: 3: 101: 0 0 SentenceNr 1 TxtType: Q Pargr: 2 ClType:ZYq0
PS009,002 SPR                 0   1  4  1 18 -1 -1    1  1  1  0    -1   1   1  -1      -1      -1      -1    0  501     0
PS009,002 KL                 -6   2 -1 -1 -1  1 -1   -1 -1  1  2     1   2   0  -1       2      -1      -1   -1   -1    -1
PS009,002 PL>                 0   1  0  3  1 12 -1    6  0  3  1     1   2   0  -1      -1      -1      -1   -1   -1    -1
PS009,002 K                  -1   7 -1 -1 -1 -1 -1   -1  2  1  2    -1   7   2   2  -20102      -1      -1    0  503     0
           * 0 -1 200 1 200 0 0 .. 4 LineNr 5 ClauseNr 1: 1: 2: 101: 0 0 SentenceNr 2 TxtType: Q Pargr: 2 ClType:ZYq0
PS009,003 FMX                 0   1  4  0 18 -1 -1    1  1  1  0    -1   1   1  -1      -1      -1      -1    0  501     0
           * 0 -1 200 1 201 2 200 0 0 .. 4 LineNr 6 ClauseNr 1: 1: 1: 101: 0 0 SentenceNr 3 TxtType: Q Pargr: 2 ClType:ZYq0
PS009,003 W                   0   6 -1 -1 -1 -1 -1   -1 -1 -1 -1    -1   6   6  -1      -1      -1      -1    0  509     0
PS009,003 <LY                 0   1  4  0 18 -1 -1    1  1  1  0    -1   1   1  -1      -1      -1      -1    0  501     0
PS009,003 B                   0   5 -1 -1 -1 -1 -1   -1 -1 -1 -1    -1   5   0  -1      -1      -1      -1   -1   -1    -1
PS009,003 K                  -1   7 -1 -1 -1 -1 -1   -1  2  1  2    -1   7   5   2      -1      -1      -1    0  504     0
           * 0 -1 201 0 0 .. 5 LineNr 7 ClauseNr 1: 1: 3: 151: 0 0 SentenceNr 4 TxtType: Q Pargr: 2 ClType:WYq0
PS009,003 ZMR                 0   1  4  1 18 -1 -1    1  1  1  0    -1   1   1  -1      -1      -1      -1    0  501     0
PS009,003 CM                  0   2 -1 -1 -1  1 -1   -1 -1  1  2     1   2   0  -1      -1      -1      -1   -1   -1    -1
PS009,003 K                  -1   7 -1 -1 -1 -1 -1   -1  2  1  2    -1   7   2   2      -1      -1      -1    0  503     0

File2
Code:
PS009,001 L          ?         
PS009,001 H          ?         
PS009,001 NYX        ?         
PS009,001 <LMWT      ?         
PS009,001 L          ?         
PS009,001 H          ?         
PS009,001 BN         ?         
PS009,001 MZMWR      ?         
PS009,001 L          ?         
PS009,001 DWD        ?         
PS009,002 JDH        JDJ       
PS009,002 ?          L         
PS009,002 JHWH       MRJ>      
PS009,002 B          MN        
PS009,002 KL         KL        
PS009,002 ?          H         
PS009,002 LB         LB        
PS009,002 J          J         
PS009,002 ?          W         
PS009,002 SPR        C<J       
PS009,002 KL         KL        
PS009,002 ?          HJN       
PS009,002 PL>        TDMWR>    
PS009,002 K          K         
PS009,003 FMX        XDJ       
PS009,003 W          W         
PS009,003 <LY        RWZ=      
PS009,003 B          B         
PS009,003 K          K         
PS009,003 ?          W         
PS009,003 ZMR        ZMR==     
PS009,003 ?          L         
PS009,003 CM         CM        
PS009,003 K          K

The awk script that I have been using is:

example$ awk -f script.awk file1 file2

Where 'script.awk' is:

Code:
FNR==NR {
         q=$2
         $1=$2=""
         A[q]=$0
         next
}
{
if($2 !~/\?/ && $1 && $2 in A)
         print $0,A[$2]
else if($2 ~/\?/)
         print $0, " - - - - - - - - - - - - - - - - - - - - - "
}

My output with the above script is:

Code:
PS009,001 L          ?            0 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 0 -1 -1 -1 -1 -1 -1 -1
PS009,001 H          ?            0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 -1 -1 -1 -1 -1 -1 -1
PS009,001 NYX        ?            0 1 7 1 1 1 -1 6 0 1 2 2 2 5 2 -1 -1 -1 0 521 0
PS009,001 <LMWT      ?            0 2 -1 -1 -1 1 -1 -1 -1 1 1 2 2 2 1 -1 -1 -1 0 521 0
PS009,001 L          ?            0 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 0 -1 -1 -1 -1 -1 -1 -1
PS009,001 H          ?            0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 -1 -1 -1 -1 -1 -1 -1
PS009,001 BN         ?            0 2 -1 -1 -1 1 -1 -1 -1 1 2 2 2 5 2 -1 -1 -1 -11 582 0
PS009,001 MZMWR      ?            0 2 -1 -1 -1 1 -1 -1 -1 1 2 2 2 2 1 -1 -1 -1 0 521 0
PS009,001 L          ?            0 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 0 -1 -1 -1 -1 -1 -1 -1
PS009,001 DWD        ?            0 3 -1 -1 -1 1 -1 -1 -1 1 2 2 3 5 2 -1 -1 -1 -11 582 0
PS009,002 JDH        JDJ          0 1 4 2 1 -1 -1 1 1 1 0 -1 1 1 -1 -1 -1 -1 0 501 0
PS009,002 ?          L           - - - - - - - - - - - - - - - - - - - - - 
PS009,002 JHWH       MRJ>         0 3 -1 -1 -1 1 -1 -1 -1 1 2 2 3 3 2 -1 -1 -1 0 562 0
PS009,002 B          MN           0 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 0 -1 -1 -1 -1 -1 -1 -1
PS009,002 KL         KL           -6 2 -1 -1 -1 1 -1 -1 -1 1 2 1 2 0 -1 2 -1 -1 -1 -1 -1
PS009,002 ?          H           - - - - - - - - - - - - - - - - - - - - - 
PS009,002 LB         LB           0 2 -1 -1 -1 1 -1 -1 -1 1 2 1 2 0 -1 -1 -1 -1 -1 -1 -1
PS009,002 J          J            -1 7 -1 -1 -1 -1 -1 -1 1 1 -1 -1 7 7 2 -1 -1 -1 0 503 0
PS009,002 ?          W           - - - - - - - - - - - - - - - - - - - - - 
PS009,002 SPR        C<J          0 1 4 1 18 -1 -1 1 1 1 0 -1 1 1 -1 -1 -1 -1 0 501 0
PS009,002 KL         KL           -6 2 -1 -1 -1 1 -1 -1 -1 1 2 1 2 0 -1 2 -1 -1 -1 -1 -1
PS009,002 ?          HJN         - - - - - - - - - - - - - - - - - - - - - 
PS009,002 PL>        TDMWR>       0 1 0 3 1 12 -1 6 0 3 1 1 2 0 -1 -1 -1 -1 -1 -1 -1
PS009,002 K          K            -1 7 -1 -1 -1 -1 -1 -1 2 1 2 -1 7 5 2 -1 -1 -1 0 505 0
PS009,003 FMX        XDJ          0 1 4 0 18 -1 -1 1 1 1 0 -1 1 1 -1 -1 -1 -1 0 501 0
PS009,003 W          W            0 6 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 6 -1 -1 -1 -1 0 509 0
PS009,003 <LY        RWZ=         0 1 4 0 18 -1 -1 1 1 1 0 -1 1 1 -1 -1 -1 -1 0 501 0
PS009,003 B          B            0 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 0 -1 -1 -1 -1 -1 -1 -1
PS009,003 K          K            -1 7 -1 -1 -1 -1 -1 -1 2 1 2 -1 7 5 2 -1 -1 -1 0 505 0
PS009,003 ?          W           - - - - - - - - - - - - - - - - - - - - - 
PS009,003 ZMR        ZMR==        0 1 1 1 7 -1 -1 3 2 3 2 -1 1 1 -1 -1 -1 -1 0 501 0
PS009,003 ?          L           - - - - - - - - - - - - - - - - - - - - - 
PS009,003 CM         CM           0 2 -1 -1 -1 1 -1 -1 -1 1 2 1 2 0 -1 -1 -1 -1 -1 -1 -1
PS009,003 K          K            -1 7 -1 -1 -1 -1 -1 -1 2 1 2 -1 7 5 2 -1 -1 -1 0 505 0

The output is mostly correct, but for instance on the next to last field on the line beginning PS009,002 JHWH (line 13) should be 503 as per file1 and in another case the line beginning PS009,003 ZMR (line 31) fields $4 until the end of the line are all incorrect.

However, if I change the order of the input files:

example$ awk -f script.awk file2 file1

I seem to get most of the data correct but the fields are out of order and naturally the "-" for when $3 in file2 is a "?" do not print.

Output:

Code:
PS009,001 L                   0   5 -1 -1 -1 -1 -1   -1 -1 -1 -1    -1   5   0  -1      -1      -1      -1   -1   -1    -1   ?
PS009,001 H                   0   0 -1 -1 -1 -1 -1   -1 -1 -1 -1    -1   0   0  -1      -1      -1      -1   -1   -1    -1   ?
PS009,001 NYX                 0   1  7  1  1  1 -1    6  0  1  2     2   2   5   2      -1      -1      -1    0  521     0   ?
PS009,001 <LMWT               0   2 -1 -1 -1  1 -1   -1 -1  1  1     2   2   2   1      -1      -1      -1    0  521     0   ?
PS009,001 L                   0   5 -1 -1 -1 -1 -1   -1 -1 -1 -1    -1   5   0  -1      -1      -1      -1   -1   -1    -1   ?
PS009,001 H                   0   0 -1 -1 -1 -1 -1   -1 -1 -1 -1    -1   0   0  -1      -1      -1      -1   -1   -1    -1   ?
PS009,001 BN                  0   2 -1 -1 -1  1 -1   -1 -1  1  2     2   2   5   2      -1      -1      -1  -11  582     0   ?
PS009,001 MZMWR               0   2 -1 -1 -1  1 -1   -1 -1  1  2     2   2   2   1      -1      -1      -1    0  521     0   ?
PS009,001 L                   0   5 -1 -1 -1 -1 -1   -1 -1 -1 -1    -1   5   0  -1      -1      -1      -1   -1   -1    -1   ?
PS009,001 DWD                 0   3 -1 -1 -1  1 -1   -1 -1  1  2     2   3   5   2      -1      -1      -1  -11  582     0   ?
PS009,002 JDH                 0   1  4  2  1 -1 -1    1  1  1  0    -1   1   1  -1      -1      -1      -1    0  501     0   JDJ
PS009,002 JHWH                0   3 -1 -1 -1  1 -1   -1 -1  1  2     2   3   3   2      -1      -1      -1    0  503     0   ?
PS009,002 B                   0   5 -1 -1 -1 -1 -1   -1 -1 -1 -1    -1   5   0  -1      -1      -1      -1   -1   -1    -1   B
PS009,002 KL                 -6   2 -1 -1 -1  1 -1   -1 -1  1  2     1   2   0  -1       2      -1      -1   -1   -1    -1   KL
PS009,002 LB                  0   2 -1 -1 -1  1 -1   -1 -1  1  2     1   2   0  -1      -1      -1      -1   -1   -1    -1   LB
PS009,002 J                  -1   7 -1 -1 -1 -1 -1   -1  1  1 -1    -1   7   5   2  -20102      -1      -1    0  505     0   NJ
PS009,002 SPR                 0   1  4  1 18 -1 -1    1  1  1  0    -1   1   1  -1      -1      -1      -1    0  501     0   C<J
PS009,002 KL                 -6   2 -1 -1 -1  1 -1   -1 -1  1  2     1   2   0  -1       2      -1      -1   -1   -1    -1   KL
PS009,002 PL>                 0   1  0  3  1 12 -1    6  0  3  1     1   2   0  -1      -1      -1      -1   -1   -1    -1   TDMWR>
PS009,002 K                  -1   7 -1 -1 -1 -1 -1   -1  2  1  2    -1   7   2   2  -20102      -1      -1    0  503     0   K
PS009,003 FMX                 0   1  4  0 18 -1 -1    1  1  1  0    -1   1   1  -1      -1      -1      -1    0  501     0   XDJ
PS009,003 W                   0   6 -1 -1 -1 -1 -1   -1 -1 -1 -1    -1   6   6  -1      -1      -1      -1    0  509     0   W
PS009,003 <LY                 0   1  4  0 18 -1 -1    1  1  1  0    -1   1   1  -1      -1      -1      -1    0  501     0   RWZ=
PS009,003 B                   0   5 -1 -1 -1 -1 -1   -1 -1 -1 -1    -1   5   0  -1      -1      -1      -1   -1   -1    -1   B
PS009,003 K                  -1   7 -1 -1 -1 -1 -1   -1  2  1  2    -1   7   5   2      -1      -1      -1    0  504     0   K
PS009,003 ZMR                 0   1  4  1 18 -1 -1    1  1  1  0    -1   1   1  -1      -1      -1      -1    0  501     0   ZMR==
PS009,003 CM                  0   2 -1 -1 -1  1 -1   -1 -1  1  2     1   2   0  -1      -1      -1      -1   -1   -1    -1   CM
PS009,003 K                  -1   7 -1 -1 -1 -1 -1   -1  2  1  2    -1   7   2   2      -1      -1      -1    0  503     0   K

Hopefully this makes sense and I really appreciate that I can turn to this forum when I am stuck.
# 2  
Old 01-05-2018
Perhaps these modifications make it more what you are looking for:
Code:
FNR==NR {
         q=$1 SUBSEP $2
         $1=$2=""
         A[q]=$0
         next
}
{
if($2 !~/\?/ && ($1,$2) in A)
         print $0,A[$1,$2]
else if($2 ~/\?/)
         print $0, " - - - - - - - - - - - - - - - - - - - - - "
}

This is using both field 1 and 2 instead of only field 2.

It produces:
Code:
PS009,001 L          ?            0 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 0 -1 -1 -1 -1 -1 -1 -1
PS009,001 H          ?            0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 -1 -1 -1 -1 -1 -1 -1
PS009,001 NYX        ?            0 1 7 1 1 1 -1 6 0 1 2 2 2 5 2 -1 -1 -1 0 521 0
PS009,001 <LMWT      ?            0 2 -1 -1 -1 1 -1 -1 -1 1 1 2 2 2 1 -1 -1 -1 0 521 0
PS009,001 L          ?            0 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 0 -1 -1 -1 -1 -1 -1 -1
PS009,001 H          ?            0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 -1 -1 -1 -1 -1 -1 -1
PS009,001 BN         ?            0 2 -1 -1 -1 1 -1 -1 -1 1 2 2 2 5 2 -1 -1 -1 -11 582 0
PS009,001 MZMWR      ?            0 2 -1 -1 -1 1 -1 -1 -1 1 2 2 2 2 1 -1 -1 -1 0 521 0
PS009,001 L          ?            0 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 0 -1 -1 -1 -1 -1 -1 -1
PS009,001 DWD        ?            0 3 -1 -1 -1 1 -1 -1 -1 1 2 2 3 5 2 -1 -1 -1 -11 582 0
PS009,002 JDH        JDJ          0 1 4 2 1 -1 -1 1 1 1 0 -1 1 1 -1 -1 -1 -1 0 501 0
PS009,002 ?          L           - - - - - - - - - - - - - - - - - - - - - 
PS009,002 JHWH       MRJ>         0 3 -1 -1 -1 1 -1 -1 -1 1 2 2 3 3 2 -1 -1 -1 0 503 0
PS009,002 B          MN           0 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 0 -1 -1 -1 -1 -1 -1 -1
PS009,002 KL         KL           -6 2 -1 -1 -1 1 -1 -1 -1 1 2 1 2 0 -1 2 -1 -1 -1 -1 -1
PS009,002 ?          H           - - - - - - - - - - - - - - - - - - - - - 
PS009,002 LB         LB           0 2 -1 -1 -1 1 -1 -1 -1 1 2 1 2 0 -1 -1 -1 -1 -1 -1 -1
PS009,002 J          J            -1 7 -1 -1 -1 -1 -1 -1 1 1 -1 -1 7 5 2 -20102 -1 -1 0 505 0
PS009,002 ?          W           - - - - - - - - - - - - - - - - - - - - - 
PS009,002 SPR        C<J          0 1 4 1 18 -1 -1 1 1 1 0 -1 1 1 -1 -1 -1 -1 0 501 0
PS009,002 KL         KL           -6 2 -1 -1 -1 1 -1 -1 -1 1 2 1 2 0 -1 2 -1 -1 -1 -1 -1
PS009,002 ?          HJN         - - - - - - - - - - - - - - - - - - - - - 
PS009,002 PL>        TDMWR>       0 1 0 3 1 12 -1 6 0 3 1 1 2 0 -1 -1 -1 -1 -1 -1 -1
PS009,002 K          K            -1 7 -1 -1 -1 -1 -1 -1 2 1 2 -1 7 2 2 -20102 -1 -1 0 503 0
PS009,003 FMX        XDJ          0 1 4 0 18 -1 -1 1 1 1 0 -1 1 1 -1 -1 -1 -1 0 501 0
PS009,003 W          W            0 6 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 6 -1 -1 -1 -1 0 509 0
PS009,003 <LY        RWZ=         0 1 4 0 18 -1 -1 1 1 1 0 -1 1 1 -1 -1 -1 -1 0 501 0
PS009,003 B          B            0 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 0 -1 -1 -1 -1 -1 -1 -1
PS009,003 K          K            -1 7 -1 -1 -1 -1 -1 -1 2 1 2 -1 7 2 2 -1 -1 -1 0 503 0
PS009,003 ?          W           - - - - - - - - - - - - - - - - - - - - - 
PS009,003 ZMR        ZMR==        0 1 4 1 18 -1 -1 1 1 1 0 -1 1 1 -1 -1 -1 -1 0 501 0
PS009,003 ?          L           - - - - - - - - - - - - - - - - - - - - - 
PS009,003 CM         CM           0 2 -1 -1 -1 1 -1 -1 -1 1 2 1 2 0 -1 -1 -1 -1 -1 -1 -1
PS009,003 K          K   -1 7 -1 -1 -1 -1 -1 -1 2 1 2 -1 7 2 2 -1 -1 -1 0 503 0

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 01-05-2018
Thank you so very much!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk match two fields in two files

Hi, I have two TEST files t.xyz and a.xyz which have three columns each. a.xyz have more rows than t.xyz. I will like to output rows at which $1 and $2 of t.xyz match $1 and $2 of a.xyz. Total number of output rows should be equal to that of t.xyz. It works fine, but when I apply it to large... (6 Replies)
Discussion started by: geomarine
6 Replies

2. Shell Programming and Scripting

awk to update file based on match in 3 fields

Trying to use awk to store the value of $5 in file1 in array x. That array x is then used to search $4 of file1 to find aa match (I use x to skip the header in file1). Since $4 can have multiple strings in it seperated by a , (comma), I split them and iterate througn each split looking for a match.... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

awk move select fields to match file prefix in two directories

In the awk below I am trying to use the file1 as a match to file2. In file2 the contents of $5,&6,and $7 (always tab-delimited) and are copied to the output under the header Quality metrics. The below executes but the output is empty. I have added comments to help and show my thinking. Thank you... (0 Replies)
Discussion started by: cmccabe
0 Replies

4. Shell Programming and Scripting

awk to print match or non-match and select fields/patterns for non-matches

In the awk below I am trying to output those lines that Match between file1 and file2, those Missing in file1, and those missing in file2. Using each $1,$2,$4,$5 value as a key to match on, that is if those 4 fields are found in both files the match, but if those 4 fields are not found then missing... (0 Replies)
Discussion started by: cmccabe
0 Replies

5. UNIX for Beginners Questions & Answers

Match Strings between two files, print portions of each file together when matched ([g]awk)

I have two files and desire to use the strings from $1 of file 1 (file1.txt) as search criteria to find matches in $2 of file 2 (file2.txt). If matches are found I want to output the entire line of file 2 (file2.txt) followed by fields $2-$11 of file 1 (file1.txt). I can find the matches, I cannot... (7 Replies)
Discussion started by: jvoot
7 Replies

6. Shell Programming and Scripting

awk to print fields that match using conditions and a default value for non-matching in two files

Trying to use awk to match the contents of each line in file1 with $5 in file2. Both files are tab-delimited and there may be a space or special character in the name being matched in file2, for example in file1 the name is BRCA1 but in file2 the name is BRCA 1 or in file1 name is BCR but in file2... (6 Replies)
Discussion started by: cmccabe
6 Replies

7. Shell Programming and Scripting

Regex: print matched line and exact pattern match

Hi experts, I have a file with regexes which is used for automatic searches on several files (40+ GB). To do some postprocessing with the grep result I need the matching line as well as the match itself. I know that the latter could be achieved with grep's -o option. But I'm not aware of a... (2 Replies)
Discussion started by: stresing
2 Replies

8. Shell Programming and Scripting

awk help: Match data fields from 2 files & output results from both into 1 file

I need to take 2 input files and create 1 output based on matches from each file. I am looking to match field #1 in both files (Userid) and create an output file that will be a combination of fields from both file1 and file2 if there are any differences in the fields 2,3,4,5,or 6. Below is an... (5 Replies)
Discussion started by: ambroze
5 Replies

9. Shell Programming and Scripting

Match a line in File 1 with Column in File 2 and print whole line in file 2 when matched

Hi Experts, I am very new to scripting and have a prb since few days and it is urgent to solve so much appreciated if u help me. i have 2 files file1.txt 9647810043118 9647810043126 9647810043155 9647810043161 9647810043166 9647810043185 9647810043200 9647810043203 9647810043250... (22 Replies)
Discussion started by: mustafa.abdulsa
22 Replies

10. Shell Programming and Scripting

awk print fields to multiple files?

I am trying to print the output of a command to two separate files. Is it possible to use awk to print $1 to one file and $2 to another file? Thanks in advance! (1 Reply)
Discussion started by: TheCrunge
1 Replies
Login or Register to Ask a Question

Featured Tech Videos