awk: bailing out at source line 1

icfantv picture icfantv · Jul 9, 2015 · Viewed 9.8k times · Source

I'm looking to get some colorized log output and don't want to use multitail.

The command I'm trying to execute is:

tail -100f some_file.log | awk '/INFO/ {print "\033[32m" $0 "\033[39m"} /Exception/ {print "\033[31m" $0"\033[39m"}'

but I'm getting the error:

awk: syntax error at source line 1
 context is
     >>> /INFO <<< / {print "\033[32m" $0 "\033[39m"} /Exception/ {print "\033[31m" $0"\033[39m"}
    4 missing ]'s
awk: bailing out at source line 1

My totally non-expert guess is that for some reason it thinks the terminal codes should have closing ]'s on them. I've tried escaping them but that doesn't work and frankly, I'm not sure that this wouldn't jack up the terminal codes.

Answer

Akshay Hegde picture Akshay Hegde · Jul 10, 2015

awk: bailing out at source line 1

If you are on a Solaris/SunOS system, change awk at the start of this script to /usr/xpg4/bin/awk or /usr/xpg6/bin/awk , or nawk