如何只查找包含两个单词

时间:2015-08-04 05:31:01

标签: linux shell

我想只查看包含两个单词之间可能有一个或多个空格的句子。

实施例

1. always  @    ( posedge clk  or     posedge rst )      //Test
2. always @ ( posedge clock )begin //or negedge reset) begin
3. always  @ (posedge clock or posedge reset)      //Test
4. always @ ( posedge clock ) //or negedge reset) begin

这里我只想grep序列号1和3.输出应该是:

1. always  @    ( posedge clk  or     posedge rst )      //Test
3. always  @ (posedge clock or posedge reset)      //Test

我怎么能grep?

1 个答案:

答案 0 :(得分:0)

将此作为输入文件(从问题来源复制并粘贴):

$ cat >file
1. always  @    ( posedge clk  or     posedge rst )      //Test
2. always @ ( posedge clock )begin //or negedge reset) begin
3. always  @ (posedge clock or posedge reset)      //Test
4. always @ ( posedge clock ) //or negedge reset) begin

我可以告诉你,你正在寻找线上任何地方有两个或更多连续空格的所有线。在那种情况下:

$ grep '  ' file
1. always  @    ( posedge clk  or     posedge rst )      //Test
3. always  @ (posedge clock or posedge reset)      //Test