2

I have a very strange problem when executing following code:

awk '{ foo = 1; switch (foo) { case 1: i=i+1; break; } }' ./tcpheader.txt

Getting following error:

awk: syntax error at source line 1
 context is
    { foo = 1; switch (foo) >>>  { <<< 
awk: illegal statement at source line 1
awk: illegal statement at source line 1

Any idea what's the problem ?

Tested on Mac:

awk --version

Output:

awk version 20070501

Tested on Ubuntu:

awk -W version

Output:

mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan

compiled limits:
max NF             32767
sprintf buffer      2040
Arsi
  • 163
  • 9

1 Answers1

2

Installing gawk solved my problem:

sudo apt-get install gawk

in mac:

sudo port install gawk
Arsi
  • 163
  • 9
  • right, `switch` is a gawk extension as clearly stated in the documentation http://www.gnu.org/software/gawk/manual/gawk.html#Switch-Statement – Ed Morton Jun 21 '15 at 13:51