Removing a text block from a file : sed ?
Posted
by
user555338
on Stack Overflow
See other posts from Stack Overflow
or by user555338
Published on 2010-12-27T20:22:39Z
Indexed on
2010/12/27
20:54 UTC
Read the original article
Hit count: 130
Hi, Following an attack, I need to remove 4 lines of text added to .htaccess files in my site, and was thinking SED would be the way to go, but cannot see how in spire of many attempts.
The added lines are
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://
RewriteCond %{HTTP_REFERER} !%{HTTP_HOST}
RewriteRule . http://targeturlhere.net/%{REMOTE_ADDR}
I managed to create the script to remove added htaccess files containing those lines only, but for existing htaccess files in which that was appended I have to edit the file and cannot delete it. I cannot just remove line by line nor use "RewriteEngine On" as the start marker, as this instruction "RewriteEngine On" is sometimes legitimate elsewhere in the file.
In most cases those lines are the last, but I guess in other files they could be in the middle, so I was trying to remove exactly that block - and have a script I could reuse in a similar case.
(Edit: my 4 lines are below one another, no blank line in between but the editor here seems to either show no breakline, or one adding a blank line)
Any hint or tip ? Thanks.
© Stack Overflow or respective owner