Problem
I have a file full of lines like
convert.these.dots.to.forward.slashes/but.leave.these.alone/i.mean.it
I want to search and replace such that I get
convert/these/dots/to/forward/slashes/but.leave.these.alone/i.mean.it
. converted to / up to the first slash
Question
How to write search and replace regular expressions to solve my problem?
Attempt to solve
I tried to use the look with perl, but the look of variable length is not implemented.
$ echo "convert.these.dots.to.forward.slashes/but.leave.these.alone/i.mean.it" | perl -pe 's/(?<=[^\/]*)\./\//g' Variable length lookbehind not implemented in regex m/(?<=[^/]*)\./ at -e line 1.
Bypass
Variable-length perspectives are implemented, so you can use this dirty trick.
$ echo "convert.these.dots.to.forward.slashes/but.leave.these.alone/i.mean.it" | rev | perl -pe 's/\.(?=[^\/]*$)/\//g' | rev convert/these/dots/to/forward/slashes/but.leave.these.alone/i.mean.it
Is there a more direct solution to this problem?
source share