Angelo
Angelo

Reputation: 5059

merging two files

I have two files (tab delimited) one file is has 4 columns and n number of rows and second file has 2 columns and n number of rows.

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

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

Any suggestions for one line bash script.

Upvotes: 6

Views: 6442

Answers (3)

MacMark
MacMark

Reputation: 6549

For tabulator try

join -t \t files1 …

Upvotes: 1

Cédric Julien
Cédric Julien

Reputation: 80761

try with join

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

to express a join between the files FILE1 and FILE2 based on the 4th field (-1 4) of FILE1 and the 2nd field (-2 2) of FILE2

Upvotes: 9

Fredrik Pihl
Fredrik Pihl

Reputation: 45644

Have a look at the join command, see guide here

Upvotes: 3

Related Questions