[正则]排除字符组

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

例如,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
原文地址:https://www.cnblogs.com/jacson/p/4802047.html