Karakas Online

3.8. Sed and awk

sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or inpu t from a pipeline). We will use sed extensively through scripts like runsed, that is a wrapper around sed that takes a “sed script”, like sedscr, containing sed commands, as a first argument and the file to be transformed as a second.

awk searches files for lines (or other units of text) that contain certain patterns. When a line matches one of the patterns, awk performs specified actions on that line. awk keeps processing input lines in this way until it reaches the end of the input files. We will use awk to split the sed processed files into header, body and footer, in order to be able to manipulate these parts separately, before reassemblying them into a final document for further processing.

Most probably, your Linux distribution has already installed sed and awk for you. In case it hasn't, use the package management tool of the distribution to install them, or compile them from the source, if you feel like.

Last updated Mon Sep 24 01:19:25 CEST 2007 Permalink: http://www.karakas-online.de/mySGML/sed-and-awk.html All contents © 2002-2007 Chris Karakas