Merge two files

I have two files (with tab delimiters), one file has 4 columns and n number of rows, and the second file has 2 columns and n number of rows.

column 4 of the first file is identical to column 2 of the second file.

I want to have a third file that contains the first four columns from file 1 and column 5 from file 2.

Any suggestions for a single line bash script.

+6
source share
3 answers

try join

join FILE1 FILE2 -1 4 -2 2 -t"tab"

to express the connection between files FILE1 and FILE2 based on the 4th field ( -1 4 ) FILE1 and the second field ( -2 2 ) FILE2

+9
source

Look at the join command, see the manual here

+3
source

For a tab, try

 join -t \t files1 … 
+1
source

Source: https://habr.com/ru/post/890906/


All Articles