The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #13 (permalink)  
Old 06-05-2009
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
Quote:
Originally Posted by Nejc View Post
It seems Im getting somethig wrong here, since I am not very keen with Shell scripting. Here is the code which I put togheter with this forum topic:

Code:
find . -type f | while read i
do
  sed "s:<?php echo '<script language='JavaScript'>function e590206b977().*<\\\/script>'; ?>::" file > temp
  if cmp temp "$y" >/dev/null
  then
    rm temp
  else
    mv temp "$y"
  fi
done
Am I doing something wrong here? ...

There are a few things that I'd change, first the variables ( highlighted ), you're using i, y, file which (I guess) you're trying to represent the same thing - the file names.
I changed them below:


Code:
find . -type f | while read file
 do
   sed "s:<?php echo '<script language='JavaScript'>function e590206b977().*<\\\/script>'; ?>::" "$file" > "$file".temp
  
   # check cmp's -s flag

   if cmp -s "$file".temp "$file" 
    then
         rm "$file".temp
    else

     # proceed with care here !!

         mv "$file".temp "$file"
   fi
 done

Quote:
I added the "function string" above, since its a Joomla site, and it might already include such a string.

That's not an issue as long as the new string is a continuos part of the initial one, but add cautiously, especially when you hit special characters. BTW the new string ( function e5... ) is not a problem.

Proceed with care when you rename the files, test first from the command line with a few files using only the sed code, to be sure you're getting the right changes.

Last edited by rubin; 06-05-2009 at 08:50 AM.. Reason: reformulated the first sentence