Thursday, January 19, 2012

why we need single quote for awk

Today I need to use awk to add extra tabs and space to a long file. Then my first awk script begins.

awk is simple: /patter/'{action}'. You will see nearly every on-line introduction will tell you to add single quote to include actions. Sometimes single quote behavior is really strange in windows, but works well under Linux.

FinallyI realize single quote must be used to preserve bash to expand some special characters,like back-slash and stars, and pass them to awk. In Windows, dos/cmd has the different ways to do it, then you need different quote, see http://www.catonmat.net/blog/wp-content/uploads/2008/09/awk1line.txt for example.

1 comment:

diwen said...

这个玩意最好用了,哈哈