The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How To replace Control-M in all files in a folder padpa Shell Programming and Scripting 10 09-02-2008 07:58 AM
Replace a string containing :/=\ in files lalelle Shell Programming and Scripting 4 08-14-2008 09:26 AM
How to learn the number of files under a particular folder, containing subfolders cy163 UNIX for Dummies Questions & Answers 5 09-01-2007 11:55 AM
Basic Q: getting list of all files of type within folder & subfolders AtomicPenguin UNIX for Dummies Questions & Answers 1 07-28-2007 07:43 AM
Need to replace a string in 100's of files calredd Shell Programming and Scripting 3 03-21-2007 05:14 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-24-2008
crazynups crazynups is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 2
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?
  #2 (permalink)  
Old 06-24-2008
crazynups crazynups is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 2
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?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:43 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0