Difference between revisions of "Awk"

From Freephile Wiki
Jump to navigation Jump to search
(reformat the pre section into mediawiki syntax)
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Examples ==
 
; get first column from mw table data
 
awk '/\|-/{getline;print}' /tmp/terror.txt | sed s/\|// | sed s/'^ *'// | sort -u
 
 
; see who's trying to SSH into your server (brute force attack)
 
awk '/Invalid user/ {print $8}' /var/log/auth.log | sort | uniq -c
 
 
== Docs ==
 
The man page for Awk is 27 pages long.  Hard to read in a terminal.  Here is [[File:Awk.pdf|a PDF copy of the Awk manual|thumb]] a PDF copy of the Awk manual
 
 
 
== One-liners ==
 
== One-liners ==
 
<pre>
 
<pre>
Line 319: Line 309:
 
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 (Aho, Kernighan, and Weinberger) Summary'''''</center>
  
  
Line 556: Line 546:
  
 
|}
 
|}
'''2007 Peteris Krumins peter@catonmat.net[http://www.catonmat.net/ http://www.catonmat.net] good coders code, great reuse'''
+
'''2007 Peteris Krumins peter@catonmat.net[http://www.catonmat.net/ http://www.catonmat.net] good coders code, great reuse'''
  
 
Variable is supported:'''Y'''
 
Variable is supported:'''Y'''
Line 626: Line 616:
 
| | '''-W lint[=value]--lint[=value]'''
 
| | '''-W lint[=value]--lint[=value]'''
  
| | Provide warnings about constructs that are dubious or non-portable to other AWK impl�s. With argument '''fatal''', lint warnings become fatal errors. With an optional argument of '''invalid''', only warnings about things that are actually invalid are issued. (This is not fully implemented yet.)
+
| | Provide warnings about constructs that are dubious or non-portable to other AWK . With argument '''fatal''', lint warnings become fatal errors. With an optional argument of '''invalid''', only warnings about things that are actually invalid are issued. (This is not fully implemented yet.)
  
 
|-
 
|-
Line 680: Line 670:
  
 
|}
 
|}
'''2007 Peteris Krumins peter@catonmat.net[http://www.catonmat.net/ http://www.catonmat.net] good coders code, great reuse'''
+
'''2007 Peteris Krumins peter@catonmat.net[http://www.catonmat.net/ http://www.catonmat.net] good coders code, great reuse'''
  
 
'''Statements and Functions:'''
 
'''Statements and Functions:'''
Line 701: Line 691:
 
|-
 
|-
 
| | '''getline'''
 
| | '''getline'''
| | Set $0 from next input record; set NF, NR, FNR. Returns 0 on EOF and �1 on an error. Upon an error, ERRNO contains a string describing the problem.  
+
| | Set $0 from next input record; set NF, NR, FNR. Returns 0 on EOF and on an error. Upon an error, ERRNO contains a string describing the problem.  
  
  

Revision as of 00:50, 30 January 2017