| Related Terms |
| • grep Command |
There are two ways to run awk. A simple awk command can be run from the command line. More complex tasks should be written as awk programs ("scripts") to a file. Examples of each are provided below.
Example: % awk 'pattern {action}' input-file > output-file
meaning: take each line of the input file; if the line contains the pattern apply the action to the line and write the resulting line to the output-file.
If the pattern is omitted, the action is applied to all lines:
% awk '{action}' input-file > output-file
By default, awk
works on files that have columns of numbers or strings that are separated by
white space (tabs or spaces), but the -F option can be used if the columns are
separated by another character. awk refers to the first column as $1, the second
column as $2, etc. The whole line referred to as $0.
Related Resources:
Command Library
Unix commands are introducted one by one, with examples.

