我试图取代/./或/././或/./././以/仅在bash脚本.我已经设法为sed创建正则表达式,但它不起作用.
variable="something/./././"
variable=$(echo $variable | sed "s/\/(\.\/)+/\//g")
echo $variable # this should output "something/"
Run Code Online (Sandbox Code Playgroud)
当我试图仅替换/./子串时,它在sed中使用正则表达式\/\.\/.请问sed的正则表达式需要更多的标志使用具有子串的乘法+还是*?
fal*_*tru 72
使用-r选项sed使用扩展正则表达式:
$ variable="something/./././"
$ echo $variable | sed -r "s/\/(\.\/)+/\//g"
something/
Run Code Online (Sandbox Code Playgroud)