sed

sed works by reading one line in, performing all the tasks it knows to perform on that one line, and then moving on to the next line. Each line is subjected to every editing command given.

The syntax for the utility is:

sed [options] '{command}' [filename]

The Substitute Command

One of the most common uses of the sed utility, and any similar editor, is to substitute one value for another. To accomplish this, the syntax for the command portion of the operation is:

sed 's/[regular expression]/[replacement text]/flags'

The flags can be any of the following:

n replace nth instance of pattern with replacement
g replace all instances of pattern with replacement
p write pattern space to stdout if a successful substitution takes place
w file Write the pattern space to file if a successful substitution takes place

sed command list

sed Tutorial