I'm writing a simple awk in redhat linux, but I found that the switch / case does not work for me. I searched the web but could not find the solution. The following is my code:
BEGIN {foo = 1; Switch (af) {case 3: print "x"; break; Case 2: print "y"; break; Case 1: Print "z"; break; Default: Print "Default"; }} I'm running awk GNU Awk 3.1.5. I got the following error:
awk -f test.awk
awk: test.awk: 3: switch (af) {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 anyone help me? Thanks!
The GAWK manual says:
switch statement 6.4.5 < / H3>
Note: This sub-section describes an experimental feature added in Gok 3.1.3. This is not enabled by default, to enable it, use - Enable-Switch option to configure when the chooser is configured and created for more information Section B.2.2.2 [Additional Configuration Option], page 26 See 9
The switch statement allows the execution of statements based on the valuation of an exchange and the case match. The statements of the case are examined for a match in which they are defined. If no suitable case is found, the default section is executed, if supplied.
Which version of gawk are you using? Was this compiled with the - enabled-switch option? If you can not tell that gawk was compiled from - Enable - shortcode and you are receiving syntax errors It is understandable that it is not so. I am using the compiled code gawk 3.1.8 with the default code and you can get as many errors you are seeing on your script, as well as get it. Given that, it is highly unlikely that your version has been compiled with the required configuration options. If you wish, it is not difficult to recompile the gawk with the option.
Comments
Post a Comment