I need to substitute some text inside a text file with a replacement. Usually I would do something like
sed -i 's/text/replacement/g' path/to/the/file
The problem is that both text and replacement are complex strings containing dashes, slashes, blackslashes, quotes and so on. If I escape all necessary characters inside text the thing becomes quickly unreadable. On the other hand I do not need the power of regular expressions: I just need to substitute the text literally.
Is there a way to do text substitution without using regular expressions with some bash command?
It would be rather trivial to write a script that does this, but I figure there should exist something already.
find and replace all– Akash May 9 '12 at 15:04bashalways ship with Microsoft Word? ;) No.. Just kidding. The OP might want to do this on a remote machine or for a batch of files though. – slhck♦ May 9 '12 at 15:07sed, which is probably a futile effort considering all the switches and platform differences. – l0b0 May 9 '12 at 15:11