Title: sed Command Review
Course: CIS 121: Linux/UNIX I: Fundamentals ~ For IGNITE Review > Section: Learning Modules

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

- Add g for global replacements (all occurrences of the string per line). (Cobbault, pp. 131)
- Add - n: character indicating no display of file content.

sed s'/abc/xyz/' file1

- Displays the content of file1 with the first "abc" on each line changed to "xyz".

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

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

- Displays the content of file1 with three stars before and after the first "abc" on the line.
- Note:  The ampersand (&) is not a regular expression character, but rather a feature of the 'sed s' command.

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

- Displays the content of file1 with parenthesis around the first "Hello" on each line.

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

- Displays the content of file1 with parenthesis around every "Hello" on every line.