Re: sed – using variables containing "/"

Johnny Rosenberg gurus.knugum at gmail.com
Sun Feb 19 13:50:29 UTC 2012


2012/2/12 Avi Greenbury <lists at avi.co>:
> Johnny Rosenberg wrote:
>> So, if the variable MyVar contains a ”/”, sed will fail and a
>> workaround is to use another character instead of the ”/” character
>> for sed, like in this case, ”@”.
>
> Yeah, rather than s/4\/3/four-thirds/ one might do s at 4/3 at four-thirds@
>
>> Is this the only workaround in this case or is there a more elegant
>> one? The variable ”MyVar” must not be changed in any way, other than
>> that, everything is allowed, I suppose…
>
> If you can't escape it, then yeah that's all you can do in sed as far
> as I'm aware. That doesn't strike me as particularly inelegant
> (especially considering how much I use sed for changing filepaths) - is
> there some other reason to not do it that way?

Well, maybe the variable in some rare cases contains one or more ”@”?

>
> If you want to be more flexible, though, and so permit all characters
> in the strings (or at least not need to predict what might be in them)
> it would probably be easiest to pipe it into a perl one-liner.
>
> --
> Avi.
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users




More information about the ubuntu-users mailing list