Find Common Values Across Two Files

Hi All,

I have two files like below:

File1

MYFILE_28012012_1112.txt|4
MYFILE_28012012_1113.txt|51
MYFILE_28012012_1114.txt|57
MYFILE_28012012_1115.txt|57
MYFILE_28012012_1116.txt|57
MYFILE_28012012_1117.txt|57

File2

MYFILE_28012012_1110.txt|57
MYFILE_28012012_1111.txt|57
MYFILE_28012012_1112.txt|57
MYFILE_28012012_1115.txt|57
MYFILE_28012012_1116.txt|57
MYFILE_28012012_1117.txt|57

I want to match value of first column in file 1 with file 2 and wish to get the output as below:

MYFILE_28012012_1112.txt|4|57
MYFILE_28012012_1115.txt|57|57
MYFILE_28012012_1116.txt|57|57
MYFILE_28012012_1117.txt|57|57

Any help on this will be highly appreciated
Thanks
Angshuman

join -t"|" -1 1 -2 1 -o 1.1 1.2 2.2 file1 file2
1 Like

or with awk...

awk -F "|" 'NR==FNR{A[$1]=$0;next}{if(A[$1]){print A[$1]"|"$NF}}' file1 file2
1 Like