I have the following line of awk code in my script which searches text between start and end patterns from logs.
Logs look similar to:
[zzzz] Static WEB3
[zzzz] capture me
[zzzz] capture me
[zzzz] capture me
[zzzz] end-pattern
OR could be
[zzzz] Static WEB1 :: WEB2 :: WEB3
[zzzz] capture me
[zzzz] capture me
[zzzz] capture me
[zzzz] end-pattern
Awk script:
awk "/\[zzzz\] Static ${VAR3} / || /${VAR1} :: ${VAR2} :: ${VAR3} /{flag=1;next} /end-pattern:/{flag=0}flag" /tmp/error.log
I got these errors:
01:18:35 awk: cmd. line:1: /\[zzzz\] Static WEB3 / || /WEB1 :: WEB2 :: WEB3 /{flag=1;next} /end-pattern:/{flag=0}flag
01:18:35 awk: cmd. line:1: ^ syntax error
01:18:35 awk: cmd. line:1: /\[zzzz\] Static WEB3 / || /WEB1 :: WEB2 :: WEB3 /{flag=1;next} /end-pattern:/{flag=0}flag
01:18:35 awk: cmd. line:1: ^ syntax error
I don't understand why I get the above syntax errors
from awk, while the above code executes perfectly on my local machine (ubuntu 16.04, with bash GNU bash, version 4.3.46(1)-release).
I also tried using \
before :
to escape however I get a different issue.
01:18:35 awk: cmd. line:1: /\[zzzz\] Static WEB3 / || /WEB1 \:\: WEB2 \:\: WEB3 /{flag=1;next} /end-pattern:/{flag=0}flag
01:18:35 awk: cmd. line:1: ^ backslash not last character on line
01:18:35 awk: cmd. line:1: /\[zzzz\] Static WEB3 / || /WEB1 \:\: WEB2 \:\: WEB3 /{flag=1;next} /end-pattern:/{flag=0}flag
01:18:35 awk: cmd. line:1: ^ syntax error
What am I missing here ?