The test command, t
, branches to a label (or the end of the script) if a
successful substitution has been made on the currently
It implies a conditional branch.
Its syntax is as follows:
is supplied, control falls through
to the end of the script.
then execution resumes at the line following the label.
Let's look at a spelling corrector written by Greg Ubben.
The script fixes common (in this example, silly) spelling goofs;
command tells about corrections that were made:
s/said editor/sed editor/g
holds a copy of the current input line.
Then, if any of the four substitutions succeed, the command
branches to the corresponding label (
at the end of the script.
Otherwise, if no
command restarts the
script on the next line (as always in sed
, the input line is printed
before the script re-starts).
After the label, the script prints the current input line (the line with
a spelling error - which, by now, has been corrected).
gets the original uncorrected line.
command brackets that line
Here's some sample output:
sed -f sedscr afile
This is a separate test.
[WAS: This is a seperate test.]
I put a label on my computer!
[WAS: I put a lable on my compooter!]
That's all for now.
in the script is a work-around for a bug in some versions
Greg says "The t
flag is supposed to be reset after either the
command is executed or a new line of input is read, but some versions
don't reset it on a new line of input.
So I added a do-nothing
to make sure it's reset after the previous
Try the script without the extra
; if adding it makes the
script work right, your sed
has the bug and you might try a new
version, like GNU gsed