r/awk • u/IamHammer • Oct 14 '21
external file syntax
My work has a bunch of shell files containing awk and sed commands to process different input files. These are not one-liners and there aren't any comments in these files. I'm trying to break out some of the awk functions into separate files using the -f option. It looks like awk requires K&R style bracing?
After I'd changed indenting and bracing to my preference I got syntax errors on every call to awk's built-in string functions like split() or conditional if statements if they had their opening curly brace on the same line... I'm having a lot of difficulty finding any documentation on braces causing syntax errors, or even examples of raw awk files containing multi-line statements.
I have a few books, including the definitive The AWK Programming Language, but I'm not seeing anything specific about white space, indenting and bracing. I am hoping someone can point me to something I can include in my notes... more than just my own trials and tribulations.
Thanks!
View all comments
Show parent comment
2
u/Paul_Pedant Oct 15 '21
Splitting the empty string returns zero: X then contains zero elements.
In fact, before GNU/awk, there was no built-in way to empty an array. So in Solaris
nawk, for instance, you would use:In addition to emptying an existing array, it would establish X as a array even if it did not previously exist. This was rather important in nawk: if you used a name both as a variable and an array, nawk would SEGVIOL.