Merge Two Files

If the two files have the same number of rows, you can merge together with ‘pr’ and then extract the column whatever you want with ‘awk’.

See man pr and man awk for details.

> cat file1
one two three
one two three
one two three
one two three

> cat file2
four five six
four five six
four five six
four five six

> pr -m -t -s\ file1 file2 | gawk ‘{print $4,$5,$6,$1}’
four five six one
four five six one
four five six one
four five six one

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: