Thursday, June 11, 2009

simple awk usage

note to self

Once again, something i can't seem to hold in my mind, and end up searching for it over and over.

Awk can be used in this way to filter out a field from a text file when the separator is a " " ( WHITE SPACE )

awk '{ print $n}'

$n - is the field/column number

This can also be used in many other things for example, -my favourite- to take out the leading white spaces on queue_ids from grep'd and cut'd ;-) postfix logs.

Thanks dhaj for showing me this trick.


Gaveen said...

The whitespace in the first example is showing, so both of them look the same.

Yajith Ajantha said...

thanks! tried to get it to show the output in the correct way, but didn't work. I just removed that part. :D