awk Commands, Examples & Meaning

Learn to use awk for text and data extraction, data processing, validation,  generate reports for analysis, automation with with the help of examples of if else , compare & arrays plus regular expressions & built in operational variables, meaning, examples &command syntax.

awk name & History

The name awk comes from the initials of its creators: Alfred V. Aho, Peter J. Weinberger, and Brian W. Kernighan.
Original version of awk was written in 1977 at AT&T Bell Laboratories.  Paul Rubin wrote gawk ( gnu awk ) in 1986.

Using awk

awk can be used directly on a command line, executed as program file or from a program file referenced by command line awk .

awk Command Line

awk can be used in command line as a tool to process and format the data from one or more input files or output of another program .

Syntax to use data file as input and run awk command to process data

awk ‘<awk command>’ <file>

Use command output as data input using PIPE processing

Command output | awk ‘<awk command>’

awk variable assignments

awk works on lines and columns and process data line by line and assigns variables to each line and column.

$0 = Entire line
$1 = First Column
$2 = Second Column
$3 = Third Column

and so on
column is defined as a word/characters surrounded by space/s . Common Linux/Unix commands like df ,ls , ps gives columnar outputs and awk is very useful in getting listing and processing column data. A print statement is used to print variables .

Working with awk commands

awk commands are enclosed in single quotes, any single quote after awk options is considered as awk command and a matching single quote is taken as as end of command.
Next Page – Awk Examples

1 thought on “awk Commands, Examples & Meaning


This site uses Akismet to reduce spam. Learn how your comment data is processed.