在正则表达式模式中,你也可以反转自读组的作用,你可以寻找组中没有的任意字符,而不是去寻找组中含有的字符。要这么做的话,只要在字符组的开头加个脱字符:

例如,data6的内容如下:

This is a test line
This is a different line.
This is a test of line
The cat is sleeping
That is a very nice hat.
at ten o'clock we'll go home
This test is at line two
hhi data6's content

匹配开头不是T开头的的

sed -n '/[^Ts]hi/p' data6

这时,所有带有hi并且开始的字符串为T和s的都滤除了。

输出:

hhi data6's content

注意,因为^也代表在首字母匹配,当把^符号移出[]内时,匹配的就是在开头是T和s开头并带有hi的字符了

sed -n '/^[Ts]hi/p' data6

输出:

This is a test line
This is a different line.
This is a test of line
This test is at line two

 

相关文章:

  • 2021-06-24
  • 2021-11-13
  • 2022-02-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
  • 2022-12-23
猜你喜欢
  • 2021-08-23
  • 2021-05-25
  • 2022-12-23
  • 2021-10-04
  • 2021-10-06
相关资源
相似解决方案