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.
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
Installing and switching to gawk
fixed the issue. Thanks to everyone who had helpful replies.
From Effective Awk Programming, Edition 4:
A Rose by Any Other Name The awk language has evolved over the years. Full details are provided in Appendix A [The Evolution of the
awk Language], page 439. The language described in this book is often
referred to as "new awk." By analogy, the original version of awk is
referred to as "old awk."
On most current systems, when you run the
awk utility you get some version of new awk.4 If your system’s
standard awk is the old one, you will see something like this if you
try the test program:
$ awk 1 /dev/null
error awk: syntax error near line 1
error awk: bailing out near line 1
In this case, you
should find a version of new awk, or just install gawk!
Throughout
this book, whenever we refer to a language feature that should be
available in any complete implementation of POSIX awk, we simply use
the term awk. When referring to a feature that is specific to the GNU
implementation, we use the term gawk.
4 Only Solaris systems still use an old awk for > the default awk utility. A more modern awk lives in /usr/xpg6/bin
on these systems.
This answer has been moved from Serching a pattern using awk and print next 15 lines from a log file