除了匹配之外,Grep得到一切


0

假设我有一个文本文件说:

Hello my name is agz.
I am asking a question that is important.

如果我输入:grep -v "is" /path/to/file,我应该没有输出,因为两行都有“是”。

如果我输入:grep -o "is" /path/to/file,我应该得到:

is
is

但是我想得到:

Hello my name agz.
I am asking a question that important.

(只是错过了)有没有办法用grep和minimal regex实现这个目的?

Answers:


9

grep不是这项工作的正确工具。sed是。

$ sed 's|is||g' test.txt
Hello my name  agz.
I am asking a question that  important.

$ sed 's|is ||g' test.txt
Hello my name agz.
I am asking a question that important.
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.