【发布时间】:2023-03-05 07:39:01
【问题描述】:
我找不到将标志与sed 和匹配模式一起使用的方法。
我正在尝试使用 i 标志。但我不明白它是如何工作的。
$ sed -i '' -n '/xxx.xxx@xxx.fr/i d' res.txt
sed: 1: "/xxx.xxx@xxx.fr/i d": command i expects \ followed by text
所以我想匹配 xxx.xxx@xxx.fr 和 XXX.XXX@XXX.FR
-i '' 仅用于--in-file (without cache),d 用于删除。
那么我怎样才能使用标志并最终使用多个标志呢?在文档中我发现它是这样的,但它似乎根本不起作用。
【问题讨论】:
-
你想做什么,用文件 res.txt 中的东西替换 xxx.xxx@xxx.fr?
-
使用 -i 标志将允许就地修改文件,而不是输出到标准输出。
-
GNU sed 有
I标志 case insensitive match.. 在 OSX 上也不确定.. -
你得到的错误可能是因为 sed 认为你想使用
i命令在匹配的模式之前插入一些东西。GNU sed 会接受这个seq 5 | sed '/3/i d'但 OSX 需要\之后i.. 所以seq 5 | sed '/3/i\ d' -
MacOS 不支持不区分大小写的匹配stackoverflow.com/questions/4412945/…