26 ms·
I have never been able to get my head around awk - how did you learn it?
by voltagex_ 8y ago
I have never been able to get my head around awk - how did you learn it?
- FelipeCortez 8y agoThe AWK programming language book is excellent! https://archive.org/download/pdfy-MgN0H1joIoDVoIC7/The_AWK_Programming_Language.pdf https://archive.org/download/pdfy-MgN0H1joIoDVoIC7/The_AWK_P... You can find some discussion about it here: https://news.ycombinator.com/item?id=13451454 https://news.ycombinator.com/item?id=13451454
- voltagex_ 8y ago>This book was typeset in Times Roman and Courier by the authors, using an Autologic APS-5 phototypesetter and a DEC VAX 8550 running the 9th Edition of the UNIX operating system. Delightful!
- patrec 8y ago"The AWK programming language" has already been suggested and is great. But awk is actually pretty simple. Imagine everything having an implicit loop like this around it like so: # BEGIN{ ... } would go here for $0 in input.split('\n'): $1, $2, ... = line.split() # if TEST {ACTION}; pairs ... # END { ... } would go here so the first TEST in GP's awk would be `$1 ~ /class|module/` and the corresponding ACTION to take `{print $2}`. if TEST is omitted it's True, if ACTION is it's print the whole line.
- svsucculents 8y agoIt's C. Learn C and you know awk. The only awk worth using is G(nu)awk anyway.
- msla 8y agoNo, in that C doesn't have the pattern-action style of awk: /<pattern>/ { <action> } "For every line which matches <pattern> perform <action> " is the fundamental flow of awk programs. It's procedural but the iteration is hidden; it's almost like each stanza is a callback which gets executed when the pattern fires. I'm kinda surprised no "real language" has adopted this design for an API.
- svsucculents 8y agoThat's the reason I love this site. Moron downvotes and rudimentary objections.
- yesenadam 8y agoSame as usual, read every book about it![0] and don't try to learn from the man page. I think the original book by A, W and K (the 2nd edition anyway) was best. Also Arnold Robbins' books Sed and Awk and Effective AWK Programming are great. The GNU Awk User's Guide[1] is amazingly detailed, but the new AWK has bloated a lot, has 1000 features where the older one had a few dozen, and those core ones should be learnt first. (But people still like programming with it, and kept asking for features..) Hmm I don't think I use any of the new features, maybe I should... But really, it's very simple, I can't thinking of anything that's been anything like as easy to learn, except maybe BASIC. With which AWK shares some similarities - the friendliness of it, the BEGIN and END.. [1] http://www.gnu.org/software/gawk/manual/gawk.html http://www.gnu.org/software/gawk/manual/gawk.html [0] Or if there are too many, get names from lists of best books on a subject.
- yesenadam 8y agop.s. Bruce Barnett's AWK guide may be helpful, I've learned a lot from him on various UNIXy subjects. http://www.grymoire.com/Unix/Awk.html http://www.grymoire.com/Unix/Awk.html