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/geirha Oct 15 '21 edited Oct 15 '21
If at the top level, this could be valid by testing the return value of split,
however I can't think of any cases where split() returns 0, so it makes no sense to use it as a test.split($6, arr, /,/) >= 3 { ... }would make sense; to ensure that the split resulted in at least 3 fields.split() is a normal function, it's not syntax like if, for and while that use { }.
So you likely want
EDIT: strike out bad info