2017-05-04 178 views
-3

排除列表中指定的字,我有以下单词列表POSIX正则表达式:使用正则表达式

www.home.example.com 
www.example.com 
home.example.com 
google.com 
example.com 
child.example.com 
sameer.example.com 
sameer.google.com 

我需要只匹配child domains of example.com,这意味着我需要回答以下正则表达式:

www.home.example.com 
home.example.com 
child.example.com 
sameer.example.com 

但是没有使用egrep -v选项。

我试过egrep -i '(([(a-zA-Z0-9\-\.|^www)]*)\.example\.com)'但没有工作。任何帮助将不胜感激。

+1

尝试'grep -v'^ red $''。 –

+0

@WiktorStribiżew,看起来像是在工作,将其作为答案,以便我可以upvote你的答案。 – manjesh23

+0

@WiktorStribiżew,但有没有办法可以跳过使用-v?因为不确定我的设备是否支持-v或不支持。我可以使用类似'!' – manjesh23

回答

0

的grep的方法(与PCRE):

grep -Pi '(?<!www)\.example\.com' file 

而不PCRE:

cat file | grep -Ei '\.example\.com' | grep -Ev '^w{3}\.example\.com' 

输出:

www.home.example.com 
home.example.com 
child.example.com 
sameer.example.com 
+0

我的设备使用POSIX,PCRE在我的设备上不受支持,我正在使用自定义内核。 – manjesh23

+0

@ manjesh23,检查我的更新 – RomanPerekhrest

+0

您仍在使用'-v'进行更新。 –

0

我不确定你想排除什么,因为你说你只想匹配给定域中的那些。如果单词在单独的行中的文件中,不应该将一个匹配锁定到行尾?

grep -e '\.example\.com$' domains 

如果要排除后的东西,就用grep -vit's part of POSIX反正。

+0

他想排除'www.example.com' – RomanPerekhrest

+0

@RomanPerekhrest,是的,样本输出丢失了。但是这个问题并没有说明排除它的规则是什么。 – ilkkachu

相关问题