4 ms·
Pardon the pun, but I've always found awk awkward to use. Literally every time I use awk I have to google the syntax because I don't use it often enough for it
by umvi 6y ago
Pardon the pun, but I've always found awk awkward to use.
Literally every time I use awk I have to google the syntax because I don't use it often enough for it to persist in long term memory.
If only awk's syntax were a subset of a language I already knew, like python or JS
- OriginalPenguin 6y agoIf awk's syntax was a subset of either python or JS, wouldn't it be better to just use python or JS?
- JadeNB 6y ago> If awk's syntax was a subset of either python or JS, wouldn't it be better to just use python or JS? Not necessarily—sometimes it makes sense to use Datalog instead of Prolog, for example.
- smcameron 6y agoI found the syntax to be like regex plus something close to C. I expect back in the day when everyone using unix was also using C, this made awk syntax pretty obvious (certainly was the case for me). But if you don't know C, I suppose the syntax might be less obvious. I use awk all the time in one liners.
- coliveira 6y agoThe great thing about awk is that 99% of what you need can be learned by just using "man awk". And if you need the remaining 1%, probably you should be using another language.
- vidarh 6y agoOr just use either a small wrapper to provide awk-like functionality, or an interpreter with explicit options for awk-like functionality. E.g. Perl and Ruby "-pe"/"-pie" command line options, and assorted related variations both offers ways to do awk-like single-liners that are just minor syntactic sugar over full scripts. But writing a tiny wrapper like that for your preferred language should be easy enough. "ruby -an -F: -e ' puts $F[0] '" is equivalent to awk -F: ' { print $1 } ' for example -n adds an implicit "while gets(); ...; end" loop; gets by default sets $_; -n adds an implicit $F = $_.split($;); -F sets $; ; -e takes what follows as a Ruby expression.