Issue
I'm trying to replace /./
or /././
or /./././
to /
only in bash script. I've managed to create regex for sed but it doesn't work.
variable="something/./././"
variable=$(echo $variable | sed "s/\/(\.\/)+/\//g")
echo $variable # this should output "something/"
When I tried to replace only /./
substring it worked with regex in sed \/\.\/
. Does sed regex requires more flags to use multiplication of substring with +
or *
?
Solution
Use -r
option to make sed
to use extended regular expression:
$ variable="something/./././"
$ echo $variable | sed -r "s/\/(\.\/)+/\//g"
something/
Answered By - falsetru Answer Checked By - Terry (WPSolving Volunteer)