O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required