6.4. When should I NOT use sed?
You should not use sed when you have "dedicated" tools which can do
the job faster or with an easier syntax. Do not use sed when you
only want to:
The tr utility is also more suited than sed to some simple tasks. For
example, to:
- delete individual characters. Instead of "s/[a-d]//g", use
tr -d "[a-d]"
- squeeze sequential characters. Instead of "s/ee*/e/g", use
tr -s "{character-set}"
- change individual characters. Instead of "y/abcdef/ABCDEF/", use
tr "[a-f]" "[A-F]"
Note, however, that tr does not support giving input files on the
command line, so the syntax is:
tr {options-and-patterns} < input-file
or, to process multiple files:
cat input-file1 input-file2 | tr {options-and-patterns}
If you have multiple files, using tr instead of sed is often more of
an exercise than a useful thing. Although sed can perfectly emulate
certain functions of cat, grep, nl, rev, sort, tac, tail, tr, uniq,
and other utilities, producing identical output, the native utilities
are usually optimized to do the job more quickly than sed.