Invoking an awk program

Last edit

Summary: syntax

Added:

> {{{ sh

Changed:

< === _Running an awk script_

to

> }}}
> === Running an awk script

Added:

> {{{ sh

Changed:

< === _Using a hashbang_
< As with other Unix scripts, an [[awk]] script can be started using a [[hashbang]]. However, because of the syntax of the [[awk]] command line, it is necessary to include a switch in the [[hashbang]] line as follows:
< #!/usr/bin/awk -f
< print "Hello World!"
< === _Using awk as a filter_

to

> }}}
> === Using a shebang (hashbang)
> As with other Unix scripts, an [[awk]] script can be started using a [[hashbang]]. However, because of the syntax of the [[awk]] command line, it is necessary to include a the -f switch in the [[hashbang]] line as follows:
> {{{ sh
> #!/usr/bin/awk -f
> BEGIN
> {

> print "Hello World!"
> }
> }}}

> === Using awk as a filter


Throwaway one-liners

It is often useful to type a simple program at the command line for use within awk. An awk program can be supplied as an [[argument?]] of the awk command:

 awk 'BEGIN {print "Hello World!"}'

Running an awk script

An awk script can be started at the command line, by passing the script name as a parameter to the awk interpreter:

 awk -f foobar.awk

Using a shebang (hashbang)

As with other Unix scripts, an awk script can be started using a hashbang. However, because of the syntax of the awk command line, it is necessary to include a the -f switch in the hashbang line as follows:

#!/usr/bin/awk -f
BEGIN
{
print "Hello World!"
}

Using awk as a filter