我有如下输入:
INa.aa................... October 2010 after its previous U.S.-based owners failed to pay debts
我的目标是将每个以字母 i
/I
开头的单词括起来。于是我下达了命令:
sed 's/\<i[^[:blank:]]*\>/(&)/gi' input_data
返回此输出:
(INa.aa)................... October 2010 after (its) previous U.S.-based owners failed to pay debts
我不明白的是,为什么 ^[:blank:]*
也不包含 INa.aa
之后的点?
感谢您的任何建议。
最佳答案
您使用 \>
“词尾”转义符。单词边界定义为
the character to the left is a "word" character and the character to the right is a "non-word" character, or vice-versa
在manual (引用 \b
)。对于 \>
,“反之亦然”不适用。
什么是“字”字?
A "word" character is any letter or digit or the underscore character.
而“非词”是所有其他的。您希望句号和空格之间的边界匹配 \>
,但事实并非如此:句号和空格都是非单词字符。单词边界在最后一个a
和第一个.
之间。
a
之间的句点也被单词边界包围,但因为不涉及任何空格,所以它是匹配的一部分。
如果您想将所有内容匹配到下一个空格,您可以跳过正则表达式中的 \>
。
关于linux - ^[ :blank:] does not match dot in sed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39155872/