« Convert decimal to sexigesimal in awk | Main | How things change in a week... »

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 %6d\n", $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.

TrackBack

TrackBack URL for this entry:
http://www.krioma.net/cgi-bin/mt_new/mt-tb.cgi/412

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on December 6, 2009 3:04 AM.

The previous post in this blog was Convert decimal to sexigesimal in awk.

The next post in this blog is How things change in a week....

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.33