3 ms·
Convince me to up my game in awk! I only use it to select the n'th word in a csv-like line. Anything more than that, I need to search stackoverflow for the inv
by ducktective 4y ago
Convince me to up my game in awk!
I only use it to select the n'th word in a csv-like line. Anything more than that, I need to search stackoverflow for the invocation.
Don't you find its syntax cumbersome?
- Beltalowda 4y ago> Don't you find its syntax cumbersome? Not really; just seems the same as most other dynamic languages. Awk does a lot of stuff for you (the "implied loop" your program runs in, field splitting) that's certainly possible (even easy) to replicate in Python or Ruby, but Awk it's just so much more convenient. I use it for things like processing the Unicode data files, making some program output a bit nicer (e.g. go test -bench), ad-hoc spreadsheets, few other things. I got started with it as I needed to process some C header files and the existing script for that was in Awk; it worked pretty well for that too. The Awk Programming Language book is pretty good. GNU Awk has a bunch of very useful extensions, but pretty much everything in the book still works and is useful today. You can get it at e.g. https://archive.org/details/awkprogrammingla00ahoa https://archive.org/details/awkprogrammingla00ahoa or https://github.com/teamwipro/learn_programing/blob/master/shell/book/The.AWK.Programming.Language.pdf https://github.com/teamwipro/learn_programing/blob/master/sh... The GNU Awk docs are also pretty decent.
- jjice 4y ago> I only use it to select the n'th word in a csv-like line. If it's not a CSV with quotes to allow for commas inside values (which I think AWK will also fail in), you can use `cut`. cut -d, -f n To delimit on a comma and select the n'th field. Reads a bit easier IMO for that common AWK use case (which I used to use AWK for all the time).