Skip to main content
added 41 characters in body; edited tags
Source Link
terdon
  • 252.2k
  • 69
  • 480
  • 718

I have a file1 with 3 columns and file2 with 4 columns on a Linux system. How do I join the two files based on the string in column 3 of file1 to the string in column 2 of file2.? File2 is a large db with many entries. ColumnColumns 3 and 2of2 of file1 and file2 respectively share only few strings. I would like to output file1 with joined file2 rows incasein case the strings match and output a dash for entries with no matches.Thanx

file1:

file1
300 100 a101
450 410 a400
670 710 a20
700 610 a340

file2

file2:

b30  a340 tttttttt 456
b500 a200 llllllll 567
b60  a101 uuuuuuuu 344
b40  a50  kkkkkkkk 223
 
output

output:

300 100 a101 b60 a101 uuuuuuuu 344
450 410 a400 -
670 710 a20  -
700 610 a340 b30 a340 tttttttt 456

I have a file1 with 3 columns and file2 with 4 columns. How do I join the two files based on the string in column 3 of file1 to the string in column 2 of file2. File2 is a large db with many entries. Column 3 and 2of file1 and file2 respectively share only few strings. I would like to output file1 with joined file2 rows incase the strings match and output a dash for entries with no matches.Thanx

file1
300 100 a101
450 410 a400
670 710 a20
700 610 a340

file2
b30  a340 tttttttt 456
b500 a200 llllllll 567
b60  a101 uuuuuuuu 344
b40  a50  kkkkkkkk 223
 
output
300 100 a101 b60 a101 uuuuuuuu 344
450 410 a400 -
670 710 a20  -
700 610 a340 b30 a340 tttttttt 456

I have a file1 with 3 columns and file2 with 4 columns on a Linux system. How do I join the two files based on the string in column 3 of file1 to the string in column 2 of file2? File2 is a large db with many entries. Columns 3 and 2 of file1 and file2 respectively share only few strings. I would like to output file1 with joined file2 rows in case the strings match and output a dash for entries with no matches.

file1:

300 100 a101
450 410 a400
670 710 a20
700 610 a340

file2:

b30  a340 tttttttt 456
b500 a200 llllllll 567
b60  a101 uuuuuuuu 344
b40  a50  kkkkkkkk 223

output:

300 100 a101 b60 a101 uuuuuuuu 344
450 410 a400 -
670 710 a20  -
700 610 a340 b30 a340 tttttttt 456
Source Link
Arora
  • 79
  • 5

join rows based on string in 2 columns of 2 files

I have a file1 with 3 columns and file2 with 4 columns. How do I join the two files based on the string in column 3 of file1 to the string in column 2 of file2. File2 is a large db with many entries. Column 3 and 2of file1 and file2 respectively share only few strings. I would like to output file1 with joined file2 rows incase the strings match and output a dash for entries with no matches.Thanx

file1
300 100 a101
450 410 a400
670 710 a20
700 610 a340

file2
b30  a340 tttttttt 456
b500 a200 llllllll 567
b60  a101 uuuuuuuu 344
b40  a50  kkkkkkkk 223

output
300 100 a101 b60 a101 uuuuuuuu 344
450 410 a400 -
670 710 a20  -
700 610 a340 b30 a340 tttttttt 456