Theodoros Emmanouilidis

Notes & Thoughts

awk Script To Merge Columns From Different Files


This is a very helpful awk script to merge columns from different files into one single file.

Suppose we have two files with two columns each and the same number of lines.
Our goal is to merge column two from the first file with column one from the second.

First we merge the two files and then we use awk to select the desired columns and print them to a new file.

pr -m -t -s\  file1 file2 | awk '{print $2,$3}' >out_file.txt
posted under Tip Of The Day