Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tips'n'tricks in awk [closed]

Tags:

idioms

awk

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...

like image 595
Łukasz Rysiak Avatar asked Feb 19 '23 17:02

Łukasz Rysiak


1 Answers

Does Awk One Liners count?

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

like image 68
danfuzz Avatar answered Feb 23 '23 12:02

danfuzz