Re: sed – using variables containing "/"



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@4/3@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?

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@xxxxxxxxxxxxxxxx
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users


Relevant Pages