[ubuntu-uk] Automating find and replace

George Carter georgealun at gmail.com
Tue Sep 16 21:09:48 UTC 2014


You can include slashes in a sed find and replace, you just need to use the escape character \ first. I.E to find http:// and replace with https:// you would use sed -i 's/http:\/\//https:\/\//g' file.php

You need to put a backslash before all of the following characters:
$.*/[\]^

Apologies if I'm stating something you already knew - I'm new to the list but figured I'd try and help out having battled with sed a fair bit.  

George

> On 16 Sep 2014, at 21:08, Gareth France <gareth.france at gmail.com> wrote:
> 
> Not ubuntu related but I'm hoping someone may have the answer I need. Today I discovered my webspace has been hacked and several sites now contain additional code at the start of every single PHP file. Looking at my backups I can see it  has been there for a while so restoring from a very old backup could cause me issues.
> 
> Is there some way I could do a recursive find and delete on that code? It is a very long single line including slashes, hashes, exclaimation marks etc so using sed would be difficult as the examples I have seen show /thing to change/thing to change to/.
> 
> Any ideas very welcome.
> 
> -- 
> ubuntu-uk at lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk
> https://wiki.ubuntu.com/UKTeam/



More information about the ubuntu-uk mailing list