Difference between revisions of "Awk"
Jump to navigation
Jump to search
(add example to get first column from mw data table) |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Examples == | == Examples == | ||
− | + | get first column from mw table data | |
awk '/\|-/{getline;print}' /tmp/terror.txt | sed s/\|// | sed s/'^ *'// | sort -u | awk '/\|-/{getline;print}' /tmp/terror.txt | sed s/\|// | sed s/'^ *'// | sort -u | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== One-liners == | == One-liners == | ||
Line 319: | Line 313: | ||
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 ( | + | <center>'''''AWK (Aho, Kernighan, and Weinberger) Summary'''''</center> |
Line 556: | Line 550: | ||
|} | |} | ||
− | ''' | + | '''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 620: | ||
| | '''-W lint[=value]--lint[=value]''' | | | '''-W lint[=value]--lint[=value]''' | ||
− | | | Provide warnings about constructs that are dubious or non-portable to other AWK | + | | | 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 674: | ||
|} | |} | ||
− | ''' | + | '''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 695: | ||
|- | |- | ||
| | '''getline''' | | | '''getline''' | ||
− | | | Set $0 from next input record; set NF, NR, FNR. Returns 0 on EOF and | + | | | 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. |