Featured Posts

Installing MathabxInstalling Mathabx Mathabx is an important symbol library for latex. The full list of available symbols in latex can be found here. Following steps will help one to install mathabx in ...

Readmore

cronScheduled Tasks using cron Learn how to schedule tasks using cron in Linux!

Readmore

Joomla!Getting started with Joomla! Joomla! is a great open source tool for making great websites with very little effort and absolutely no cost ...

Readmore

Rss

Extracting fields from multiple files using awk

1

Posted by Arsh | Labels: awk, Linux | Posted on Sunday, February 7, 2010

Say, you have two files file1 and file2 containing data in the tabular form in 3 columns each and you want to extract column 2 of file1 and column 1 of file2. We can do it using the combination of paste and awk commands as follows:

paste file1 file2 | awk '{print $2 " " $4}'


We can do more! Suppose you want to add column 1 of file1 to column 3 of file2. This can be accomplished using the following command:

paste file1 file2 | awk '{print $1-$6}'