The Basics of awk and sed

Many similarities exist between awk and sed:

  • Both have similar invocation syntax.

  • Both execute a set of programmer specified instructions on every line in their input files.

  • Both use regular expressions to find string and matching lines.

For those of you who are not familiar with regular expressions, they will be explained shortly.

Invocation Syntax

The invocation syntax for awk and sed is as follows:

							cmd 'script' files
						

Here cmd is either awk or sed, script is a list of commands understood by awk or sed, and files is a list of files that cmd acts on.

The single quotes around script are required to prevent the shell from accidentally performing substitutions. The actual contents of script differ greatly between awk and ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition 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.