我有一个字符串
file="this-is-a-{test}file"
我想从这个字符串中移除{test}
。
我使用了
echo $file | sed 's/[{][^}]*//'
但是这个返回了我
this-is-a-}file
我该如何删除}
呢?
谢谢!
我有一个字符串
file="this-is-a-{test}file"
我想从这个字符串中移除{test}
。
我使用了
echo $file | sed 's/[{][^}]*//'
但是这个返回了我
this-is-a-}file
我该如何删除}
呢?
谢谢!
作为替代方案,也可以尝试使用这个仅限于Bash的单行命令:
s="this-is-a-{test}file"
echo ${s/\{test\}/}
sed
工具:s="this-is-a-{test}file"
sed 's/{[^}]*}//' <<< "$s"
this-is-a-file
或者这个awk:
awk -F '{[^}]*}' '{print $1 $2}' <<< "$s"
this-is-a-file