print when column match with other file

Hello all, please help. There are two file like this:

file1:

1197510.0    294777.7  9666973.0                          21.6      1839.8
 1197510.0    294777.7  9666973.0                         413.2      2075.9
 1197510.0    294777.7  9666973.0                         689.3      2260.0
 1197510.0    294777.7  9666973.0                         955.4      2431.9 
 1197532.0    295017.3  9667342.0                          49.2      1884.5
 1197532.0    295017.3  9667342.0                         351.6      2043.2
 1197554.0    295257.0  9667711.0                         420.7      2092.8
 1197576.0    295496.6  9668080.0                         365.5      2057.2      
 1197576.0    295496.6  9668080.0                         669.2      2250.0      
 1197576.0    295496.6  9668080.0                         902.7      2401.4

file2:

10007 4018 9666973.0
10029 4018 9667342.0
10051 4018 9667711.0
10073 4018 9668080.0

if 3rd column of file1 match with 3rd column of file2, print like this:

1197510.0    294777.7  9666973.0      4018     10007      21.6      1839.8
 1197510.0    294777.7  9666973.0      4018     10007     413.2      2075.9
 1197510.0    294777.7  9666973.0      4018     10007     689.3      2260.0
 1197510.0    294777.7  9666973.0      4018     10007     955.4      2431.9 
 1197532.0    295017.3  9667342.0      4018     10029      49.2      1884.5
 1197532.0    295017.3  9667342.0      4018     10029     351.6      2043.2
 1197554.0    295257.0  9667711.0      4018     10051     420.7      2092.8
 1197576.0    295496.6  9668080.0      4018     10073     365.5      2057.2
 1197576.0    295496.6  9668080.0      4018     10073     669.2      2250.0
 1197576.0    295496.6  9668080.0      4018     10073     902.7      2401.4

thank in advance,

-attila

join -1 3 -2 3 file1 file2 | awk '{print $2,$3,$1,$7,$6,$4,$5}' OFS="\t"

Guru.

1 Like