Sample Header Ad - 728x90

Merging 2 files with based on field match

4 votes
3 answers
21776 views
I want to create a file that contains columns from two input files. File1 is like:
aa 32
bb 15
cc 78
File2 is:
fa 19
bc 23
cc 50
de 28
aa 45
bb 31
The task is, read through File1, if the 1st field of a row exists among the 1st field of File2, then print that line of File2, with both columns and add the 2nd column entry of File1 containing the 1st field. The output should be like:
aa 45 32
bb 31 15
cc 50 78
awk is preferred for the script.
Asked by hldn (41 rep)
Oct 8, 2014, 04:16 AM
Last activity: Mar 22, 2024, 10:06 AM