Find and Replace string in all files recursive using grep and sed

bash, grep, linux, recursion, sed

Solution

As @Didier said, you can change your delimiter to something other than `/`:

grep -rl $oldstring /path/to/folder | xargs sed -i s@$oldstring@$newstring@g

Problem

I'm getting a ``` sed: -e expression #1, char 22: unterminated `s' command ``` is there a problem on my script? Also the "oldstring" has special characters ``` #!bin/bash oldstring='<script>"[oldscript]"</script>' newstring='<script>"[newscript]"</script>' grep -rl $oldstring /path/to/folder | xargs sed -i s/$oldstring/$newstring/g ```

Original source

Related problems