Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   Recursive Search And Replace (https://www.warriorforum.com/programming/123855-recursive-search-replace.html)

Chris Ramsey 12th September 2009 03:51 PM

Recursive Search And Replace
 
Hey Warriors,

Looks like my server has been hacked again. Ugh.

Anyway, I need to get my hands on a recursive search and replace script in PHP or PERL.

I could write one myself, but frankly, I'm sure there's a million of them out there.

If you know of one with good documentation, please list it. I need to get this taken care of ASAP.

Thanks.

TristanPerry 12th September 2009 03:58 PM

Re: Recursive Search And Replace
 
Ultraedit has this. Can use regular expressions for the search and replaces.

Not sure if it goes through multiple files though.

Dreamweaver (you could always download the trial) definitely does go through all files in a folder, though.

Chris Ramsey 12th September 2009 04:04 PM

Re: Recursive Search And Replace
 
I'm hoping to avoid reg exp, first of all because I want to shoot myself when I use them, and secondly it's one string that I need to remove from every file on my server.

Quote:

Originally Posted by TristanPerry (Post 1177304)
Ultraedit has this. Can use regular expressions for the search and replaces.

Not sure if it goes through multiple files though.

Dreamweaver (you could always download the trial) definitely does go through all files in a folder, though.


TristanPerry 12th September 2009 05:11 PM

Re: Recursive Search And Replace
 
You can use both UltraEdit's and Dreamweaver's search and replace normally (by string) too; I was just pointing out that they have powerful features (whereby you can use regexes) if needed.

But yeah, they're both suitable for a simple search and replace :)

Chris Ramsey 12th September 2009 05:33 PM

Re: Recursive Search And Replace
 
Quote:

Originally Posted by TristanPerry (Post 1177484)
You can use both UltraEdit's and Dreamweaver's search and replace normally (by string) too; I was just pointing out that they have powerful features (whereby you can use regexes) if needed.

But yeah, they're both suitable for a simple search and replace :)

Thanks Tristan.

P.S. Good on you for the Firefly avatar ;)

ereadergold 12th September 2009 06:02 PM

Re: Recursive Search And Replace
 
UltraEdit would work great for this task.

Another fine choice is PS Pad, unlike UltraEdit it's a free text editor (to be fair you can download a free trial of UltraEdit):

editor PSPad - freeware HTML editor, PHP editor, XHTML, JavaScript, ASP, Perl, C, HEX editor

Bill

Chris Ramsey 12th September 2009 06:05 PM

Re: Recursive Search And Replace
 
These sound good, but all the files are server-side, and I'd like to keep them there.

So, if I can find something I can run via SSH, that would be best. That's why I'd like one in PHP or PERL. BASH may even work well.

mojojuju 12th September 2009 09:22 PM

Re: Recursive Search And Replace
 
This is what I do:

Code:

find ./ -type f | xargs sed -i 's/What you want to find/Whatever you want to replace it with/g'

Mr.Tambourine 12th September 2009 11:41 PM

Re: Recursive Search And Replace
 
I think I know what your problem is .... your PC is infected with a virus... Scan your entire PC with a good antivirus (QuickHeal,Avira) ...... also, some types of viruses delete the bottom part of the page.... so simple replacing may not work ....

I use lacehost.com for hosting (do not go by their site design) and they really are very helpful in these matters .....

CMartin 13th September 2009 01:21 AM

Re: Recursive Search And Replace
 
Quote:

Originally Posted by Chris Ramsey (Post 1177580)
These sound good, but all the files are server-side, and I'd like to keep them there.

So, if I can find something I can run via SSH, that would be best. That's why I'd like one in PHP or PERL. BASH may even work well.

Check this page:
Recursive search and replace (with a combination of bash, find and perl)
(it's a tutorial with step by step info and code)

HTH
Carlos

Chris Ramsey 13th September 2009 08:56 AM

Re: Recursive Search And Replace
 
Quote:

Originally Posted by Mr.Tambourine (Post 1178154)
I think I know what your problem is .... your PC is infected with a virus... Scan your entire PC with a good antivirus (QuickHeal,Avira) ...... also, some types of viruses delete the bottom part of the page.... so simple replacing may not work ....

I use lacehost.com for hosting (do not go by their site design) and they really are very helpful in these matters .....

Yeah, the server got hit by something. The majority of the files now have a stupid one liner at the very bottom that attaches lots of virus's to whoever views the page.

Chris Ramsey 13th September 2009 08:58 AM

Re: Recursive Search And Replace
 
Quote:

Originally Posted by mojojuju (Post 1177896)
This is what I do:

Code:

find ./ -type f | xargs sed -i 's/What you want to find/Whatever you want to replace it with/g'

Thanks! I actually tried using something very similar to this, but I can't remember what the response was. It wasn't something good, cause the problem didn't go away.

I'll give this a shot real quick and see what happens.

Chris Ramsey 13th September 2009 09:20 AM

Re: Recursive Search And Replace
 
Quote:

Originally Posted by Chris Ramsey (Post 1178934)
Thanks! I actually tried using something very similar to this, but I can't remember what the response was. It wasn't something good, cause the problem didn't go away.

I'll give this a shot real quick and see what happens.

This is the error I was getting - and still am.

Quote:

sed: can't read ./wp-content/plugins/post-thumb/STRUCTURE: No such file or directory
sed: can't read youtube.txt: No such file or directory
I get it for each file.


All times are GMT -6. The time now is 01:03 AM.