Awk Command Syntax

The awk command has the following command syntax :-

Awk [ -f program-file ] [ -Fc ] [ program ] [ variable=value ]

When using the awk command there are two important aspects we have to specify. We have to tell awk which data we wish to process (the input data) and then how we wish to process it (the awk program instructions). Awk lets us do this in several ways...

The Input Data

The Awk Program

As well as specifying the awk program and input data we can also specify other things such as the input field seperator and the intial state of variables we use in our code. The following list summarises all of the command line options available and what each option's purpose is:

Command Line Option Purpose
-f program-file The -f program-file option specifies the file containing the awk program code to execute, and is used as an alternative to writing the code on the command line with the program source option.
program source The program source command line option is used to specify awk code on the command line itself. If this option is used the awk code is best enclosed in single quotes (') to protect it from the shell.
-Fc The -Fc command line option allows you to specify the field seperator (FS) character. By default this is set to whitespace (SPACE and TAB). To set the field seperator to the number zero you would add -F0 or -F"0" to the command line.
variable=value This option enables us to initialise variables on the command line. To do this we use the format variable=value, which will set the appropriate variable to its related value prior to execution.
filenames... This is the file or list of files containing the input data we wish to process.

In order to complete this tutorial package you will be required to program some awk code through a WWW front end. You will not need to know all the details mentioned above as the WWW user interface is much friendlier than UNIX's (although it would be beneficial).

If you are still alittle unsure about the awk command line syntax you might like to look at the UNIX online help pages for awk.

[Help] [Provide some feedback] [Go to Previous Page]