4

I'm looking for caveats, tips'n'tricks etc. for awk. For example:

awk '$9=="404"{a[$7]++}END{for(i in a)print a[i],i}' access.log|less

this code, will print errors aggregated by page path.

There is a trick, to sort an array by setting WHINY_USERS to any, nonzero value, to automatically use isort function on array before printing:

WHINY_USERS=1 awk '$9=="404"{a[$7]++}END{for(i in a)print a[i],i}' access.log|less

This code will return same errors but sorted by the key name (path).

I'm looking for more tricks like this one - do you know any resource which has them listed? could you share best tricks you know? I've never found awk wiki - only same old tuts repeated over and over...

4

2 回答 2

4

Awk One Liners 算不算?

http://www.pement.org/awk/awk1line.txt

于 2012-07-28T01:48:51.013 回答
4

在 4.0 版gawk中有一个调试器。

http://www.gnu.org/software/gawk/manual/html_node/Debugger.html

Starting dgawk is exactly like running awk. The file(s) containing
the program and any supporting code are given on the command line
as arguments to one or more -f options. (dgawk is not designed to
debug command-line programs, only programs contained in files.) In
our case, we call dgawk like this:

     $ dgawk -f getopt.awk -f join.awk -f uniq.awk inputfile
于 2012-07-28T14:35:31.607 回答