DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Manipulating text with sed

What is sed?

sed is a tool which allows you to perform large-scale, noninteractive editing tasks. For example, sed can replace all the occurrences of a given word in a file with a different word, or delete all lines containing a target string from a file. sed is particularly good at working with large files or running complicated sequences of editing commands on a file or group of files from within a shell script; sed is usually faster than ed at performing global substitutions within a file.

The sed program is derived from ed, although there are considerable differences between the two, resulting from the different characteristics of interactive and batch operation. sed is best thought of as a relative of the grep family of commands: just as grep is primarily a tool for searching for regular expressions in files, so sed is a tool for carrying out regular expression based search and replace operations on files.

sed works on only a few lines of input at a time and does not use temporary files, so the only limit on the size of the files you can process is that both the input and output fit simultaneously on your disk. You can apply multiple ``global'' editing changes to your text in one pass.

Note, however, that sed lacks relative addressing (the ability to specify a line number to work on relative to the current line number) because it processes a file one line at a time and never backs up. Also, note that sed gives you no immediate verification that a command has altered your text in the way you actually intended. For this reason, you should check your output carefully.


© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 22 April 2004