Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging two files horizontally and formatting

Tags:

unix

paste

I have two files as follows:

File_1

Austin
Los Angeles
York
San Ramon

File_2

Texas
California
New York
California

I want to merge them horizontally as follows:

Austin       Texas
Los Angeles  California
York         New York
San Ramon    California

I am able to merge horizontally by using paste command, but the formatting is going haywire.

Austin Texas
Los Angeles California
York New York
San Ramon California

I realize that paste is working as it is supposed to, but can someone point me in the right direction to get the formatting right.

Thanks.

like image 914
visakh Avatar asked Feb 19 '23 15:02

visakh


1 Answers

paste is using a tab when 'merging' the file, so maybe you have to post-process the file and remove the tab with spaces:

paste File_1 File_2 | awk 'BEGIN { FS = "\t" } ; {printf("%-20s%s\n",$1,$2) }'

result:

Austin              Texas
Los Angeles         California
York                New York
San Ramon           California
like image 122
Chris Avatar answered Feb 26 '23 21:02

Chris