How to mass Search & Replace in text files.

Jamon Camisso jamon.camisso-H217xnMUJC0sA/PxXw9srA at public.gmane.org
Fri May 1 17:21:34 UTC 2009


Lance F. Squire wrote:
> D. Hugh Redelmeier wrote:
>>
>> Your question about recursive searching shows that you haven't got a
>> good internal model about how the shell ecosystem works.
>>
> 
> Is it showing!... ;)
> 
> I have only used shell to do basic file moves/renames and launching 
> other programs.
> 
>> If you want recursion, you generally have to use find(1).  The latest
>> BASH (which you probably don't have) adds ** for this purpose.
>>
> 
> Thought so, but doesn't hurt to ask. (much... :) )
> 
>> Here's a guess.  Untested.  Any bug might be very destructive.
>>
>>   find /root/of/tree/with/html -name '*.html' -print0 \
>>   | xargs --no-run-if-empty --null sed -i -e 's/BadJS//g'
>>
> 
> So far the make-up of the JS has foiled my attempts at 's/JS//'.
> 
> I tried manually \ escaping the JS in a perl script, to no avail.
> 
> As this script is between the </head> and <body> tags, can we say 
> 'everything between'?
> 
>> Notes:
>>
>>
>> - are you sure that this is all the damage that needs fixing?
>>   Proving that would seem tough and a mistake might be bad.
> 
> All the files are (supposed to be) raw html. No scripts etc.

Lots of different ways to solve this problem it sounds like. Why don't 
you post a sample segment of infected code e.g. between your 
<body></body> tags on somewhere like pastebin.ca (or in an email if 
people agree).

I propose that with said code, anyone on the list who is interested 
write a program/script/command etc. to solve said problem and submit 
them somewhere -- we could try doing everything through the wiki, 
starting with the sample code.

Then after a few submissions we have a vote in which solution is the 
best for x,y,z reasons etc. Submissions could be anonymous or attributed.

Any takers?

Jamon
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list