I'm trying to find and replace the contents of a file using grep and sed.

grep "#!/bin/bash" ./ | sed xargs -i 's/#!/bin/bash/#!/usr/bin/env bash'

How do I make sure that the string #!/bin/bash will parse as string and not confused the demiliter /?

  • Use ´\´ to escape '/' in your search/replacement strings.
    – user260419
    Apr 18 '14 at 7:28
  • As a sidenote, I assume you meant /usr/bin/env?
    – ssmy
    Apr 18 '14 at 19:05
  • yes thats what i meant @ssmy. Apr 29 '14 at 20:30

You can either escape the / with \ or use a different delimiter for sed.

Sed can also use delimiters like _ or %

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.