Using sed

sed is a stream editor that performs a set of actions on every line of its input. This allows sed to be used as a filter. The basic syntax of a sed command is

sed 'script' files

Here files is a list of one or more files, and script is one or more commands of the form

/pattern/ action

where pattern is a regular expression and action is one of the commands given in Table 16.4. If pattern is omitted, action is performed for every line of input.

Table 16.4. Some of the Actions Available in sed
Action Description
p Prints the line (p as in print)
d Deletes the line (d as in delete)
s Substitutes one expression with another (s as in substitute)

Printing Lines

Let's start with the simplest feature available in sed—printing a line that ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.