Re: Suggest new fixed flag for s command?
Aurelio Jargas <[email protected]>
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <CABMdp-Eqif6CBS14P1FtsPJ=z2KO=gf9sKRY3hgbsgeS_8Go9g@mail.gmail.com> |
I like that suggestion. I have also needed that behavior many times. And
not just in s///, but in addressing in general.
It would be nice to have a generic way of specifying a fixed string in the
address. Borrowing your f flag idea, it could be something as:
/foo/f, /bar/f { ... }
But this can be confused with a possible f command.
Anyway, regardless of the chosen syntax, I would like to have a fixed
string flag to use in sed addresses and s///. Not a global command line
flag as grep, but an individual flag to use just in the required places.
On Wednesday, May 8, 2013, 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.
>
>
>
>
> ------------------------------------
>
> --
> Yahoo! Groups Links
>
>
>
>
--
Aurelio | www.aurelio.net | @oreio
[Non-text portions of this message have been removed]