Re: [ubuntu-uk] Automating find and replace

2014-09-16 Thread Gareth France
I do keep regular backups however the issue is that this has been sitting silently for some time and changes made since the last clean backup would have been lost. On 17 Sep 2014 07:16, "Colin Law" wrote: > On 16 September 2014 21:08, Gareth France wrote: > > Not ubuntu related but I'm hoping s

Re: [ubuntu-uk] Automating find and replace

2014-09-16 Thread Colin Law
On 16 September 2014 21:08, Gareth France 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

Re: [ubuntu-uk] Automating find and replace

2014-09-16 Thread Simon Greenwood
On 16 September 2014 23:54, Gareth France wrote: > > >> Quoting from my 1979 Unix manual Brian W Kernigan (who is the K in awk) >> says 'there is nothing sacred about slashes' so you can do s?http:// >> ?https://? In other words 'any character can be used to delimit the >> pieces of the s comman

Re: [ubuntu-uk] Automating find and replace

2014-09-16 Thread Gareth France
Quoting from my 1979 Unix manual Brian W Kernigan (who is the K in awk) says 'there is nothing sacred about slashes' so you can do s?http://?https://? In other words 'any character can be used to delimit the pieces of the s command' It can save a lot of back slash escaping. Tony Thank

Re: [ubuntu-uk] Automating find and replace

2014-09-16 Thread Tony Pursell
On 16 September 2014 22:09, George Carter wrote: > 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 befor

Re: [ubuntu-uk] Automating find and replace

2014-09-16 Thread Bruno Girin
Assuming the offending line is always the same, here's what I would do: Create a file called evil-hack where you copy the offending line, then run a script like this: find . -name "*.php" -print | while read f; do cp $f $f.hacked grep -f evil-hack -F -v $f.hacked > $f done So to unpack those

Re: [ubuntu-uk] Automating find and replace

2014-09-16 Thread George Carter
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

Re: [ubuntu-uk] Automating find and replace

2014-09-16 Thread Josh Holland
Hi Gareth, On Tue, 16 Sep 2014, at 09:56 PM, Gareth France wrote: Eh? Simon has given a quick account of the traditional Unix file searching tools, grep, find and xargs (which isn't technically a searching tool but is very often used with them). They are very powerful, but take a good amount

Re: [ubuntu-uk] Automating find and replace

2014-09-16 Thread Gareth France
Eh? On 16/09/14 21:29, Simon Greenwood wrote: On 16 September 2014 21:08, Gareth France > 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 addi

Re: [ubuntu-uk] Automating find and replace

2014-09-16 Thread Simon Greenwood
On 16 September 2014 21:08, Gareth France 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 ha

[ubuntu-uk] Automating find and replace

2014-09-16 Thread Gareth France
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 b