home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 34.1 Two Things You Must Know About sed Chapter 34
The sed Stream Editor
Next: 34.3 Testing and Using a sed Script: checksed, runsed
 

34.2 Invoking sed

If you were using sed on the fly, as a stream editor (34.1 ) , you might execute it as simply as this:

% somecommand

 | sed 's/old/new/' | 

othercommand

Given filenames, sed will read them instead of standard input:

% sed 's/old/new/' myfile

A simple script can go right on the command line. If you want to execute more than one editing command, you can use the -e option:

% sed -e 's/old/new/' -e '/bad/d' myfile

or you can use semicolons (; ), which are a sed command separator:

% sed 's/old/new/; /bad/d' myfile

or (especially useful in shell scripts (1.5 ) ) you can use the Bourne shell's ability to understand multiline commands:

sed '
s/old/new/
/bad/d' myfile

or you can put your commands into a file, and tell sed to read that file with the -f option:

% sed -f scriptfile myfile

There's only one other command-line option: -n . sed normally prints every line of its input (except those that have been deleted by the editing script). But there are times when you only want lines that your script has affected, or that you explicitly ask for with the p command. In these cases, use -n to suppress the normal output.

- TOR


Previous: 34.1 Two Things You Must Know About sed UNIX Power Tools Next: 34.3 Testing and Using a sed Script: checksed, runsed
34.1 Two Things You Must Know About sed Book Index 34.3 Testing and Using a sed Script: checksed, runsed

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System