Suggest new fixed flag for s command?

"Daniel" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
I have run into a situation sometimes where literal strings I want to replace that have metacharacters, and I want to replace it with some other similarly odd string.

For example, suppose I want to replace the literal string "jj*hh" with the literal string "foo\1bar".

To make it work, I would have to use escape characters:

$ echo 'jj*hh' | sed 's/jj\*hh/foo\\1bar/'
foo\1bar

I don't mind doing this for one or two strings, but sometimes I have a lot of strings, and don't want to escape them all by hand or write some complex script procedure.

What if the s command could have a f "fixed" flag, similar to the grep -F fixed flag, so the following would work:

$ echo 'jj*hh' | sed 's/jj*hh/foo\1bar/f'
foo\1bar

The f flag would tell s to ignore all metacharacters, to just interpret A and B in s/A/B/f as fixed strings.

Maybe there is some simpler way to do this I am overlooking? Anyway, just a suggestion.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.