Recursive Search And Replace

12 replies
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.
#recursive #replace #search
  • Profile picture of the author TristanPerry
    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.
    Signature
    Plagiarism Guard - Protect Against Content Theft
    {{ DiscussionBoard.errors[1177304].message }}
    • Profile picture of the author Chris Ramsey
      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.

      Originally Posted by TristanPerry View Post

      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.
      {{ DiscussionBoard.errors[1177318].message }}
  • Profile picture of the author TristanPerry
    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
    Signature
    Plagiarism Guard - Protect Against Content Theft
    {{ DiscussionBoard.errors[1177484].message }}
    • Profile picture of the author Chris Ramsey
      Originally Posted by TristanPerry View Post

      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
      {{ DiscussionBoard.errors[1177520].message }}
  • Profile picture of the author mywebwork
    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
    {{ DiscussionBoard.errors[1177575].message }}
  • Profile picture of the author Chris Ramsey
    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.
    {{ DiscussionBoard.errors[1177580].message }}
    • Profile picture of the author mojojuju
      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'
      Signature

      :)

      {{ DiscussionBoard.errors[1177896].message }}
      • Profile picture of the author Chris Ramsey
        Originally Posted by mojojuju View Post

        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.
        {{ DiscussionBoard.errors[1178934].message }}
        • Profile picture of the author Chris Ramsey
          Originally Posted by Chris Ramsey View Post

          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.

          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.
          {{ DiscussionBoard.errors[1178977].message }}
    • Profile picture of the author CMartin
      Originally Posted by Chris Ramsey View Post

      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
      {{ DiscussionBoard.errors[1178244].message }}
  • Profile picture of the author Mr.Tambourine
    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 .....
    {{ DiscussionBoard.errors[1178154].message }}
    • Profile picture of the author Chris Ramsey
      Originally Posted by Mr.Tambourine View Post

      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.
      {{ DiscussionBoard.errors[1178930].message }}

Trending Topics