Misplaced Pages

Sed: Difference between revisions

Article snapshot taken from[REDACTED] with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Browse history interactively← Previous editNext edit →Content deleted Content addedVisualWikitext
Revision as of 22:10, 14 July 2002 edit195.186.131.4 (talk)No edit summary← Previous edit Revision as of 04:09, 1 August 2002 edit undoHirzel (talk | contribs)1,146 edits added substitute commandNext edit →
Line 5: Line 5:
:generate_data | sed -e 's/x/y/' :generate_data | sed -e 's/x/y/'
That is, generate the data, ''but'' make the small change of replacing ''x'' by ''y''. That is, generate the data, ''but'' make the small change of replacing ''x'' by ''y''.

An often used command is just to substitute expressions
:sed -e 's/OldExpression1/NewExpression/g' aFileName

The ''s'' stands for substitute, the ''g'' stands for global. That means in the whole line. After the first slash there is the expression to search for and after the second slash there is the expression to substitute instead. The first expression can be a ].


Sed is one of the very early unix commands that permitted command line processing of data files. Cousin to the later ], sed allowed powerful and interesting data processing to be done by shell scripts. Sed was probably the earliest Unix tool that really encouraged regular expressions to be used ubiquitously. Sed is one of the very early unix commands that permitted command line processing of data files. Cousin to the later ], sed allowed powerful and interesting data processing to be done by shell scripts. Sed was probably the earliest Unix tool that really encouraged regular expressions to be used ubiquitously.

Revision as of 04:09, 1 August 2002

Sed is a UNIX utility which allows to modify text files. It reads in its input line by line, transforms these lines according to rules specified in a certain simple language, and outputs them. The rules often involve regular expressions. "Sed" stands for Stream EDitor. In a typical unix pipe command, you might say something like

generate_data | sed -e 's/x/y/'

That is, generate the data, but make the small change of replacing x by y.

An often used command is just to substitute expressions

sed -e 's/OldExpression1/NewExpression/g' aFileName

The s stands for substitute, the g stands for global. That means in the whole line. After the first slash there is the expression to search for and after the second slash there is the expression to substitute instead. The first expression can be a regular expression.

Sed is one of the very early unix commands that permitted command line processing of data files. Cousin to the later AWK, sed allowed powerful and interesting data processing to be done by shell scripts. Sed was probably the earliest Unix tool that really encouraged regular expressions to be used ubiquitously.

Sed and AWK are often cited as the progenitors and inspiration for Perl.

Sed's language does not have variables and only primitive GOTO and branching functionality; nevertheless, the language is Turing complete.


Sed is the Latin word for but and the Spanish word for thirst. (See also false friend.)

Sed: Difference between revisions Add topic