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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replacing text in multiple directories/files

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.
 
The one-liner should be perfect! Thanks for your help.

Nathan
 
Hello try this,
this works for all kind of files in all working dir and subdirctories except source file in working dir.
we can modify it to work ony for subdirectory files and not for pwd.


#!/bin/ksh
#script to search through all the files in the subdirctories.

find . -type f >subdir_file
temp_subdir_file=`cat subdir_file`
for i in $temp_subdir_file
do
echo the filecont=$i

if [ $i != ./serandrep.sh ] ;
then
sed 's/oranges/apples/g' $i|tee $i
fi

done

#end of the script.


Regards,
Santosh.K.B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top