0
votes

I want to check (each line) if values from file1 (in column $2 && $3) are somewhere included in file2 (in column $1 && $2). If yes, then I would like to print $1, $2, $3 from file1 as well as $3 from file2 (as a 4th column).

File1:

@ 139.51 -62.48
@ 137.36 -63.36
@ 135.44 -64.09

File2:

137.35 -63.36 6.349
137.36 -63.36 6.348
137.37 -63.36 6.346

I've got so far:

awk 'NR == FNR {a[$1$2];c[FNR] =$3;next} $2$3 in a {print $1, $2, $3, c[FNR]}' $file2 $file1 > $output 

But somehow, the resulting values in $4 are not equal to the 3rd column of file2. Could someone help me out? Thank you so much! :)

I am new in programming, and use awk and shell so far, so I am always happy about explanations! Thank you!

1
What is expected output?anubhava
The expected output in this case should be: @ 137.36 -63.36 6.348IsiSa
@IsiSa, then I think you got the answer, posted below :) enjoy learning cheers. Please do post your expected outputs too in code tags for people's easiness.RavinderSingh13
@RavinderSingh13, thanks so much! That really helped me a lot! And thanks for the note - it's my second question here, so not much used to it yet :)IsiSa
@IsiSa, not an issue, see this stackoverflow.com/help/someone-answers and keep enjoying learning and sharing knowledge here.RavinderSingh13

1 Answers

2
votes

Since you haven't shown your expected output, so based on your statements only writing this code.

awk 'FNR==NR{a[$2,$3]=$0;next} (($1,$2) in a){print a[$1,$2],$NF}' fiLE1  fiLE2

Output will be as follows.

@ 137.36 -63.36 6.348