Awk: Difference between revisions
From Jedisaber Wiki
No edit summary |
No edit summary |
||
| Line 4: | Line 4: | ||
<code>awk <i>pattern</i> {<i>action</i>}</code> | <code>awk <i>pattern</i> {<i>action</i>}</code> | ||
== Structure == | |||
<code>BEGIN</code> The begin block runs at the start of the awk program, and runs only once. | |||
== Operators == | |||
<code> \ </code> The \ tells awk that a special character follows the slash, and to interpret it differently than regular text | <code> \ </code> The \ tells awk that a special character follows the slash, and to interpret it differently than regular text | ||
| Line 11: | Line 18: | ||
<code> $ </code> field (column) reference | <code> $ </code> field (column) reference | ||
Example: <code>$2</code> tells awk to do something to the 2nd field (column) of the input | Example: <code>$2</code> tells awk to do something to the 2nd field (column) of the input. (Note that awk does not interpret variables inside strings.) | ||
<code></code> | <code></code> | ||
Revision as of 16:42, 30 December 2016
awk parses reports, among other text manipulation
Usage:
awk pattern {action}
Structure
BEGIN The begin block runs at the start of the awk program, and runs only once.
Operators
\ The \ tells awk that a special character follows the slash, and to interpret it differently than regular text
Example: \t means a tab character
$ field (column) reference
Example: $2 tells awk to do something to the 2nd field (column) of the input. (Note that awk does not interpret variables inside strings.)
