Replace string in all files in a folder and subfolders. | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Replace string in all files in a folder and subfolders.

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-24-2008
crazynups crazynups is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 24 June 2008, 4:15 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Replace string in all files in a folder and subfolders.

i need to change string in all files in current folder and all subfolders. i wrote the following script. It works good except it dont delete temp file from subfolders.

for z in `find . -type f -name "*.html" -o -name "*.htm"`; do
sed -e 's@abc@xyz@g' $z>temp;
mv temp $z;
done

any idea? or any other better solution?
Sponsored Links
    #2  
Old 06-24-2008
crazynups crazynups is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 24 June 2008, 4:15 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by danmero View Post
Code:
for z in `find . -type f -name "*.html" -o -name "*.htm"`; do
sed -e 's@abc@xyz@g' $z>temp;
mv temp $z && rm temp;
done

Thanks it worked


need some more guidence

i also need to make changes according to file types like this


Code:
for z in `find . -type f -name "*.PHP"`; do
sed -e 's@123@456@g' $z>temp;
mv temp $z && rm temp;
done

for z in `find . -type f -name "*.html" -o -name "*.htm"`; do
sed -e 's@abc@xyz@g' $z>temp;
mv temp $z && rm temp;
done

any other better way to do this instead of using 2 loops?
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
unique words in files of folder and its subfolders Dworza Homework & Coursework Questions 9 03-14-2011 03:24 AM
How to obtain a count of files in a folder and it's subfolders scarfinv UNIX for Dummies Questions & Answers 2 10-29-2010 03:16 PM
Shell script delete log files from folder & subfolders on space usage saha Shell Programming and Scripting 3 03-22-2009 10:56 PM
How to learn the number of files under a particular folder, containing subfolders cy163 UNIX for Dummies Questions & Answers 5 09-01-2007 10:55 AM
Basic Q: getting list of all files of type within folder & subfolders AtomicPenguin UNIX for Dummies Questions & Answers 1 07-28-2007 06:43 AM



All times are GMT -4. The time now is 10:20 AM.