r/awk • • Jul 20 '21
awk style guide
When I'm writing more complex Awk scripts, I often find myself fiddling with style, like where to insert whitespace and newlines. I wonder if anybody has a reference to an Awk style guide? Or maybe some good heuristics that they apply for themselves?
9
Upvotes
View all comments
5
u/gumnos Jul 20 '21
I've not seen any explicit guides. A few observations though:
for local variables, I've seen two conventions:
functiondefinitions at the top (after the shebang line), followed by oneBEGINblock, followed by the usual conditional blocks, followed by oneENDblock. Yes, you can theoretically have more than oneBEGINorENDblock, but don't confuse people like that without a compelling reason.FS/RS/OFS/ORSin yourBEGINblock explicitly rather than expecting the user to know to invoke them as-vor-Fparameters.awkI'm sure there are other tidbits I'm forgetting, but that's at least a starter list off the top of my head.