I have a very long and complex string in many files and I want to remove/replace it recursively. The string contains many slashes, backslashes and spaces and any kind of special signs. How do I do that? A simple find + sed combination wouldn't work because of all the special signs in it which I hardly can escape.
Would it be possible to write the search string to a file and use this as input for a search & replace command?
Best Answer
I assume that the string can contain any character except newlines and null bytes. You can quote the string for use as a sed pattern. The characters
$*./[\^
need to be preceded by a backslash. In the replacement text, you need to quote the characters\&/
.If you have Perl available, it's simpler.
To act on all the files in the current directory and its subdirectories recursively:
or