V
V
Vlad2021-07-30 12:02:17
Regular Expressions
Vlad, 2021-07-30 12:02:17

How to bulk replace strings in files via SSH?

The files on the server have become infected with a virus.
Find all files with the following occurrence and delete this occurrence:

<FilesMatch ".(PhP|php5|suspected|phtml|py|exe|php|asp|Php|aspx)$">
 Order allow,deny
 Deny from all
</FilesMatch>
<FilesMatch "^(postfs.php|votes.php|index.php|wjsindex.php|lock666.php|font-editor.php|ms-functions.php|contents.php|jsdindex.php|wp-login.php|load.php|template-load.php)$">
 Order allow,deny
 Allow from all
</FilesMatch>
AddType application/x-httpd-cgi .sh


I'm trying to do it with the command
find . -type f | xargs -d "\n" perl -pi -e 's/search/replace/g'


Instead of search, you need to register a regular expression for the searched text. I can't do it...
Help, please!

It looks like this code should work, but it doesn't work.
find . -type f | xargs -d "\n" perl -pi -e 's/<FilesMatch.*\n\s*.*\n\s*.*\n<\/FilesMatch>/replace/g'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Armenian Radio, 2021-07-30
@gbg

It's best to roll a backup instead of costing

L
Leonid Sopov, 2021-08-10
@leonidas

1. I may be wrong, but it seems to me that you are reading line by line. subtract the whole thing by adding $/=undef
2. make it too complicated, add /smso that the dot includes line wrapping
3. maybe you need to take the minimum block,
you roughly need something like

$/ = undef; s{ <FilesMatch .*? /FilesMatch> }{replace}gxsm

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question