As stated sed(1) has modified the input and written it to standard output. For mailing this letter we have to redirect the outcome to file with something like $ sed -e 's/Jennifer/Sally/' -e 's/brown/blue/' letter.jennifer >letter.sally

The example from the previous section is not too difficult, an easily digested porridge. As an exercise to move beyond this stage and to become a 'real (wo)man', we will modify an '/etc/tttys' so we can connect to a computer with a serial connection. No more watery gui/desktop soup with hieroglyphs for us!

-n By default, each line of input is echoed to the standard output
after all of the commands have been applied to it. The -n option
suppresses this behavior.

By using this option we prevent the complete file from being echoed, both modified and unmodified lines. To force 'sed' to show us the changed line, we have to specify the p modifier in the /^tty00/ pattern.

For all lines containing the 'tty00' sequence at the beginning of the line, perform all commands between the starting "{" and closing "}".

Saving a copy with a '#" in front.

Code:

/^tty00/ {
h
s/^/# /
p
g
p
}

Explanation:

Code:

h : save the current line (pattern space) into hold space
do not delete pattern space
s/^/# / : replace the null string at begin of line ('^') with a
'#' followed by a space
p : print the modified line from pattern space
g : get the line from hold space into pattern
space, and overwrite whatever is in pattern space
p : print the line from pattern space

A quick comment on "1.3 Modifying the '/etc/ttys' file", FreeBSD sed has the -i option, which makes editing files a bit easier:

Code:

-i extension
Edit files in-place similarly to -I, but treat each file indepen-
dently from other files. In particular, line numbers in each
file start at 1, the ``$'' address matches the last line of the
current file, and address ranges are limited to the current file.
(See Sed Addresses.) The net result is as though each file were
edited by a separate sed instance.

And

Code:

-I extension
Edit files in-place, saving backups with the specified extension.
If a zero-length extension is given, no backup will be saved. It
is not recommended to give a zero-length extension when in-place
editing files, as you risk corruption or partial content in situ-
ations where disk space is exhausted, etc.
Note that in-place editing with -I still takes place in a single
continuous line address space covering all files, although each
file preserves its individuality instead of forming one output
stream. The line counter is never reset between files, address
ranges can span file boundaries, and the ``$'' address matches
only the last line of the last file. (See Sed Addresses.) That
can lead to unexpected results in many cases of in-place editing,
where using -i is desired.

__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.