Using Awk to add a column to a file

I had a need to add an extra column of numbers (all the same) to dataset the other day… so simple todo with an awk script

#!/usr/bin/awk -f
BEGIN {
}
{
printf(“%10d %10d %6dn”, $1, $2 ,”10″);
}

Just save the above input like something like add_column.awk, make it executable (something like chmod 700 add_column.awk) and run it (the above just adds “10” to each line and is simple to change to a variable or some other string):

add_column.awk yourinputfile > youroutputfile

and job done.

Advertisements

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: