Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

merging two files

Tags:

bash

shell

unix

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.

like image 766
Angelo Avatar asked Jun 20 '11 08:06

Angelo


People also ask

How do I combine PDF files for free?

Select the files you want to merge using the Acrobat PDF combiner tool. Reorder the files if needed. Click Merge files. Sign in to download or share the merged file.

Can I merge files in Google Drive?

You can directly merge Google Documents with your drive.


2 Answers

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

like image 123
Cédric Julien Avatar answered Sep 22 '22 00:09

Cédric Julien


Have a look at the join command, see guide here

like image 34
Fredrik Pihl Avatar answered Sep 20 '22 00:09

Fredrik Pihl