Hi ,
I have a directory structure as dir and subdirectories and files under it and so on.now I need to find the files which contain the search string under every dir and subdir and replace .
my search string is like
searchstring=/a/b
string to be replaced=/a/c/b
please help.
many thanks,
mohan
i think this will do
sed 's/\/a\/b/\/a\/c\/b/g' filename
sweavo
August 15, 2008, 9:55am
3
make sure your files are in source control before trying this!
sed -i 's/from/to/g' `find . -name \*.ext`
hi,
thanks for the replies. i have used them but not working..
see the code i have used :
echo "Enter the FullPackage DIR path[/eur/development ......] "
read PKG_DIR
echo " Enter the Source Pattern to be replaced "
read SS
echo " Enter the Target Pattern "
read TS
list=`find $PKG_DIR -type f`
for file in ${list}
do
#in the below command colon is a separator
sed 's:"${SS}":"${TS}":g' ${file} > /tmp/temp.txt
mv /tmp/temp.txt ${file}
done
what is wrong with my code ?
thanks for the help
Use double quotes instead of single quotes in your sed statement, the single quotes prevent the shell to expand the variables:
sed "s:"${SS}":"${TS}":g" ${file} > /tmp/temp.txt
hi franky,
thanks a lot for the help. working fine..
thanks
mohan
Cheers, this does work fine as long as the filenames do not contain spaces!
How can I adapt it to handle spaces in filenames correctly?
H.
hamaryns:
Cheers, this does work fine as long as the filenames do not contain spaces!
How can I adapt it to handle spaces in filenames correctly?
H.
Try to quote the find command like this:
sed -i 's/from/to/g' "`find . -name \*.ext`"
Regards