I am writing a simple awk in redhat linux,but found switch/case doesn't work for me. I searched on web, but didn't find a solution. The following is my code:
BEGIN {
foo = 1;
switch (foo) {
case 3:
print "x";
break;
case 2:
print "y" ;
break;
case 1:
print "z" ;
break;
default:
print "default" ;
}
}
the awk I am running is GNU Awk 3.1.5. I got the following err:
awk -f test.awk
awk: test.awk:3: switch (foo) {
awk: test.awk:3: ^ syntax error
awk: test.awk:5: case 3:
awk: test.awk:5: ^ syntax error
awk: test.awk:8: case 2:
awk: test.awk:8: ^ syntax error
awk: test.awk:11: case 1:
awk: test.awk:11: ^ syntax error
awk: test.awk:14: default:
awk: test.awk:14: ^ syntax error
can anybody please help me out? thank you!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…