The sed command is very complex and powerful.  One of the many things that sed can do is display the contents of a file while searching for a pattern (limited regular expression), and replacing the found pattern with some new data.

One command syntax: sed 's/pattern/new_data/' filename:

By default sed acts on only the first occurrence of a matched pattern. The pattern is a limited regular expression.

NOTE:


Examples

Among the many things that sed (the stream editor) can do is perform editing functions in the stream, using regular expressions.

sed -n '2,5p' file1

sed '4,7s/abc/ABC/g' file1

sed '/abc/d' file1

An ampersand (&) can be used in the second part to recall the matched pattern.

sed 's/abc/***&***/' files

sed 's/Hello/(&)/' file1

sed 's/Hello/(&)/g' file1