Re: Suggest new fixed flag for s command?
Thierry Blanc <[email protected]>
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <[email protected]> |
very good idea. to not escape strings by hand, you can use preprocessing, something like: echo 'jj*hh.?' | sed 's|[.?*]|\\&|g' On 05/08/2013 11:27 AM, Daniel wrote: > 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. > > > > > ------------------------------------ >