AWK - AWK Commands

Commands used by AWK can come from two locations:


Assuming a file, test.txt, exists with the following contents:

10   Peter     Terence   Roux        45
11   Virginia  Genevieve  Roux       45
12   Felix     Devon     Roux         5
13   David     Bruce     Stevenson   48
14   Bob       James     Smith       16
48   Adam      Winter    Ridley      23

Simple Command File

Assuming a command file exists with following contents:

awklist
{print $2,$3}
{print $4,$5,"\n"}

Issue the following command:

awk -f awklist test.txt

returns:

Peter Terence
Roux 45

Virginia Genevieve
Roux 45

Felix Devon
Roux 5

David Bruce
Stevenson 48

Bob James
Smith 16

Adam Winter
Ridley 23

NOTE: The apostrophes are not used anywhere within the source file or when calling it at the command line.

  • They are only for use in differentiating the commands on the command line from file names.