Search and replace

Is there a way to do search _and_ replace on the command line? the grep family are fine for doing matches, but they don't so substitutions. I can write up a Perl script, but it seems such a fundimental task for an OS to do (Red Hat 6.0).
Who is Participating?
tmossConnect With a Mentor Commented:
sed 's/regexp/replacement/g' input.file > output.file

This say to search the file input.file for the regular expression and substitute the replacement string then write the results to output.file. The g option means global - substitue every occurance, not just the first.
Search and replace can be done with perl, sed, or awk on the command line.
Using sed you can also specify more than one search/replace couple, but the input file will be re-read from beginning to end for each couple.

That behaviuor leads to unexpteced result if a replace part of a couple is present in the search part of another couple.

search xx, substitute with yy
search yy, substitute with zz

Result: all xx occurrences AND all yy occurrences replaced with zz

To avoid this I developed a program that can do multiple search/replace in a SINGLE PASS. It is called 'opmsr' an acronym for One Pass Multiple Search Replace. You can download it from my home page at the following URL:

All Courses

From novice to tech pro — start learning today.