Awk: Difference between revisions
No edit summary |
m Add image |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
[[File:Application-x-awk.svg|thumb]] | |||
== Examples == | == Examples == | ||
; get first column from mw table data | ; get first column from mw table data | ||
| Line 5: | Line 7: | ||
; see who's trying to SSH into your server (brute force attack) | ; see who's trying to SSH into your server (brute force attack) | ||
awk '/Invalid user/ {print $8}' /var/log/auth.log | sort | uniq -c | awk '/Invalid user/ {print $8}' /var/log/auth.log | sort | uniq -c | ||
Tricky use of Output Record Separator (ORS) to use '''space''' instead of newline between records. Oddly enough, you don't need to escape the double quote within the double quote because the awk command is in single quotes. | |||
; print a apt purge command for all the 'removed' 'configured' packages on your system | |||
echo "apt purge $(dpkg -l | egrep '^rc' | awk 'ORS=" " {print $2}')" | |||
== Docs == | == Docs == | ||
| Line 319: | Line 325: | ||
http://www.catonmat.net/blog/wp-content/plugins/wp-downloadMonitor/user_uploads/awk.cheat.sheet.pdf | http://www.catonmat.net/blog/wp-content/plugins/wp-downloadMonitor/user_uploads/awk.cheat.sheet.pdf | ||
<center>'''''AWK ([[wp:Alfred_Aho Aho]], [[wp:Peter_J._Weinberger Weinberger]], & [[wp:Brian_Kernighan Kernighan]]) Summary'''''</center> | <center>'''''AWK ([[wp:Alfred_Aho|Aho]], [[wp:Peter_J._Weinberger|Weinberger]], & [[wp:Brian_Kernighan|Kernighan]]) Summary'''''</center> | ||