3 ms·
> Unsurprisingly I disagree with the post's description of awk being an "advanced command". I think it can be pretty advanced, for me awk is one of those tools
by nickjj 5y ago
> Unsurprisingly I disagree with the post's description of awk being an "advanced command".
I think it can be pretty advanced, for me awk is one of those tools where I still feel like I need to write a paragraph of comments to explain 1 line of code.
For example: https://github.com/nickjj/invoice/blob/75660dce5a29ceb4e47a6cea4a574b45d15548bb/invoice#L11-L30 https://github.com/nickjj/invoice/blob/75660dce5a29ceb4e47a6...
Keep in mind I don't really "know" awk. I cobbled that together from a few examples. It will convert times formatted like "2h 30m", "150m" or "2:30" into 2.50. There's a bunch of examples in the test file.
NOTE: I wrote that script 2.5 years ago and I know there's questionable patterns in other areas of the script that's not highlighted like using a bunch of separate echo calls instead of a heredoc.
Shell scripting is really fun and efficient. I use it all the time for a variety of things.
- nicce 5y agoawk is Turing-complete, so if that is not enough to describe ”advanced” tool, then I don’t know what it is.
- cross 5y agoSo is sed.
- vlovich123 5y agoI’d classify basic search/replace functionality of sed as “basic” - you see such scripts frequently enough in shell scripts. Same for awk and “extract fields 1 and 3”. Anything beyond that quickly escalates into intermediate and advanced usages. Often you can find an SO post for lots of intermediate usages (where you can just include it as a link saying “I’m trying to do X”) but advanced usages that require knowledge of that are best avoided unless you are investing in sed/awk expertise in your team. Usually choosing something like Python, Ruby, Node or even Perl can provide better value because all of those languages can solve the same problem and solve other problems those tools can’t.