Awk does not work as expected with double quotes

March 22, 2007 – 2:54 am

Of course, I felt like an idiot after being completely confused by this for about half an hour.

Consider this:

awk "{print $1}" somefile.txt

This does not work as I had expected. The reason is because the $1 is evaluated within double quotes, (not single quotes). Yes, it’s a rookie mistake, but I never claimed to be the awk master.

So, always write:


awk '{print $1}' somefile.txt

and you will avoid a headache.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit

Post a Comment