linux - ^[ :blank:] does not match dot in sed

标签 linux bash sed

我有如下输入:

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/

相关文章:

mysql - 端口重定向

ls - 在不创建无限循环的情况下向基本 bash 命令添加内容

bash - emacs shell 模式下的命令历史记录

bash - 使用sed将一些大写字符替换为小写字符

bash - 查找包含特定字符串的文件并删除包含该字符串的行 - SSH、SED

c - 如何在Linux中编写完全透明的C/C++包装程序

c++ - Linux下的socket开发

linux - 使用 webhooks 设置网络服务器部署的标准方法

用于查找总磁盘和硬盘驱动器编号的 linux 命令

regex - sed 正则表达式不工作