Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have two files. In each file I have two columns. I need to match the first value of column two of file1 with each value from column two of file2. If they are equal I need to put the two columns (column one from file1 and file2) in one file, but they should be adjacent to each other. If the two values do not match, do nothing.

file1

344  0
465  1
729  2
777  3
676  4
862  5

file2

766  0
937  1
980  2
837  3
936  5

Example output:

344    766
465    937
729    980
777    837
862    936
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
210 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you insist this be done in awk

awk 'NR == FNR {arr[$2] = $1; next} {if ($2 in arr){print(arr[$2], $1)}}' file1 file2

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...