In 30 files in 30 directories, I want to find:

script>');} < /script>

and replace it with:

script>');} < /script-->
  • What special characters do I need to escape in the find field?
  • Do I need to escape the same characters in the replace_with field?
  • Is backslash the appropriate escape key?

I will use the following method:

find . -type f -name "*.php" -exec sed -i 's/"find"/"replace_with"/g' {} +

That method has worked for simple replacements.

I read How can I replace a string in a file(s)?, and other pages, but could not find the answer I need.

  • sed "s^script>');} < /script^&--^g"
    – Costas
    Feb 11, 2016 at 22:24

1 Answer 1


you can use sed -i "s+< /script>+< /script-->+g". So final command would become

find . -type f -name "*.php" -exec sed -i "s+< /script>+< /script-->+g" {} +

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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