从字符串bash中删除一个单词
发布时间:2020-12-16 01:50:21 所属栏目:安全 来源:网络整理
导读:我有字符串 file="this-is-a-{test}file" 我想从此字符串中删除{test}. 我用了 echo $file | sed 's/[{][^}]*//' 但是这让我感动了 this-is-a-}file 我怎么能删除}? 谢谢 解决方法 你可以使用正确的正则表达式sed: s="this-is-a-{test}file"sed 's/{[^}]*}
我有字符串
file="this-is-a-{test}file" 我想从此字符串中删除{test}. echo $file | sed 's/[{][^}]*//' 但是这让我感动了 this-is-a-}file 我怎么能删除}? 谢谢 解决方法
你可以使用正确的正则表达式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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |