0

I am a sed newbie, and the lack of finding a robust, thought-free way to do this after 15 minutes of web searching is rather off-putting. I want to use sed to find an arbitrary string literal, and replace with another one - without having to "think". Meaning, once I have to look in the strings and figure out what characters to escape, this is "too much work" and I'm going to use another tool (like unix replace, which is on my sytem, much less powerful, but easy). There has got to be a simple way to tell sed that a string is a literal, not a regex, don't process it, don't touch nuthin, just take it as-is no matter how messy (well, I am content with single-line strings). So, something like:

sed s/'First messed up search string with crazy chars ##..[]{}()^*#^&^@&$^@*^$@'/'2nd crazy string *&@(&($&@($&@ foo'/  oldfile > newfile

I am not interested in answers that use a tool besides sed (bash, perl, replace, etc), or anything that requires me to read or think about the string content. Goal is no thinking about the strings!

Gilles Quénot
  • 31,569
  • 7
  • 64
  • 82
D Strozzi
  • 43
  • 4
  • Thank you Gilles, yes, that indeed does work! And I didn't find it on my own. The construct is a bit "ugly", not like just putting a string in backquotes or something to make sed treat it as literal and not regex. But, it is generic for any (one-line?) string, so it works. – D Strozzi Jan 11 '23 at 16:02

0 Answers0