3 ms·
One trick I use with awk, especially throwaway ones, is to use grep to subset the data before feeding it into awk. Often the case is using awk to poke at some
by gumby 7y ago
One trick I use with awk, especially throwaway ones, is to use grep to subset the data before feeding it into awk. Often the case is using awk to poke at some data to diagnose a problem, not write a script to be run often or stuck in cron.
So to use an example from this nice short article: I might do grep GET log-file | awk blah-blah. Then awk doesn’t need to consider the lines I don’t care about. This is especially useful when iteratively writing the awk script.
- yiyus 7y agoI find easier to do awk /GET/{blah-blah}
- gumby 7y agoOh yeah, sure! I should have been clear that when dredging a really large log file or such it can be faster to run awk on a much smaller subset when your awk program has a lot of productions. I find it easier to think "OK, just run awk on these lines that matter." Six of one half dozen of the other.