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