Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replacing text with sed

Status
Not open for further replies.
Jun 19, 2001
86
US
I need to know how to search through all files that are located within subdirectories and substitute "apples" for "oranges". This is on an HPUX box. I guess sed would work best for this. Not sure where to begin. Thanks in advance.

Nathan
 
Nationavon's query is already answered in Unix Scrpting forum Dickie Bird (:)-)))
 
Here's a handy PERL one-liner to do that:

[tt]perl -p -i -e 's/foo/bar/g' `find . -type f`[/tt]

Otherwise you could try:

[tt]for f in `find . -type f`
do
sed 's/oranges/apples/g' $f > $f.$$
mv $f.$$ $f
done[/tt]

...or something like that. It may not preserve file permissions and ownership though. Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top