4 ms·
I use awk when I need something a bit more powerful than "grep"/"cut", but don't want to pull out the big guns with Perl. For example, recently I needed to pri
by AceJohnny2 7y ago
I use awk when I need something a bit more powerful than "grep"/"cut", but don't want to pull out the big guns with Perl.
For example, recently I needed to print out certain fields of an output, but only for a given subset. So I used Awk to create a simple state machine (enable when I see the start of the subset, disable at the end), and print the fields of interest.
- AceJohnny2 7y agoOr you could use it to solve the Towers of Hanoi game ;) https://rosettacode.org/wiki/Towers_of_Hanoi#AWK https://rosettacode.org/wiki/Towers_of_Hanoi#AWK
- rmetzler 7y agoThe grep/cut replacement is exactly what I use awk the most for. I use it for other things too but this stands out. awk just fixes the problem when you need to have more than one field from the input and maybe a different string between them. I guess this can be done with cut too, but for me it's simpler this way. Also I use awk often in scripts together with fzf to interactively switch contexts e.g. in cloud provider CLIs.