1

After hacking I need clean some code add to first line on too many files.

<?php $somevar = 'some code....... ?><?php

I need clean between and include <?php $somevar and ?> because latest <?php can to be different such <html and others.

If use this I need two steeps, because not clean delimiters. I need delete delimiters also.

sed -i.bak 's/\(<?php $drnrwsrl\).*\(?>\)/\1\2/' file.php

Result

<?php $drnrwsrl?><?php

Instead of what I want

<?php
1
  • Can you re-edit your input line to include your actual output.
    – Inian
    Feb 3, 2017 at 16:58

2 Answers 2

2

Try

sed -i.bak -E 's/(<\?php.*\(?>)(<\?php)/\2/' file.php
1
  • sed: -e expresión #1, carácter 29: ) ó \) desemparejados
    – abkrim
    Feb 3, 2017 at 16:39
1

Using BRE without backreference:

sed -i.bak 's/<?php \$somevar[^>]*><?php/<?php/' file.php

To apply only to first line:

sed -i.bak '1s/<?php \$somevar[^>]*><?php/<?php/' file.php
1
  • A lot of tahnks. Best and more clean, because i need only check on first line
    – abkrim
    Feb 3, 2017 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.