【发布时间】:2017-08-23 19:19:32
【问题描述】:
我有一个删除多余空格的 sed oneliner:
sed -e 's/^\s*//' -e 's/\s*$//' -e 's/\s{2,}/ /g'
当我在" \tone1 two\t3three\t " 上对其进行测试时,sed 删除了行首和行尾的空格,但与单词之间多余的空格不匹配,并且 sed 返回\tone1 two\t3three。我想要的是\tone1 two 3three,所以sed -e 's/[ \t]{2,}/ /g' 不起作用。
regexr.com 将表达式显示为函数式。
我的版本是 GNU sed 版本 4.2.1。
【问题讨论】:
-
我认为大括号需要转义。但无论如何你都不需要它们。只需
's/\s\+/ /g'。
标签: sed