Bash substitute and match case?

Johnny Rosenberg gurus.knugum at
Fri Jan 30 22:01:37 UTC 2015

$ x="Johnny Rosenberg"
$ echo "${x//[rR]/l}"
Johnny losenbelg

Works like expected, but what if I want r→l and R→L? Can this be done with
one statement? Is there some ”follow original case” feature? ”If you find a
capital r, replace it with a capital l”
I know I can do it in two steps or one step (kind of) in sed, but that's
not what I'm asking here. I'm not going to use it for anything special, I
just want to know… I don't even know if this is possible at all with this
kind of syntax…

So in the example above, I want the following output:
Johnny Losenbelg

Kind regards

Johnny Rosenberg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the ubuntu-users mailing list