9.1. Calling awk

There are three ways awk can be invoked. You can either specify awk on the command line like this:

awk [-F field-separator] 'commands' input-file(s) 

where ‘commands’ are the actual awk commands. This method is the one that we will use most in this chapter.

In the above example the use of the -F field separator is optional, as awk uses the <space> as a default field separator. So if you are scanning text which has spaces between fields you don’t have to specify this option; however if you’re scanning the passwd file, for example, then those fields are separated by a colon, so you’ll have to state this with the -F option, like this:

awk -F: 'commands' input-file 

The second method is to insert all the awk commands in a file then ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.