2016-06-24 25 views
0

我希望有一個正則表達式下面輸入grep的非匹配端口號@服務器

echo "[email protected] [email protected] [email protected] [email protected]"| grep -Po 'regexp' 

我想輸出不包含1280字,如下

[email protected] [email protected] 
+2

你問題不清楚。請更正確地解釋它 – Arijit

+0

是否要空格分隔單詞,然後返回每個不包含1280的單詞? – AbhiNickz

+0

'perl -E'@ a = split/\ s + /,q {1280 @ lic1 1728 @ lic1 [email protected] 1924 @ lic1};對於grep!/ 1280 /,@ a'' – stevieb

回答

1
$ echo "[email protected] [email protected] [email protected] [email protected]" | sed 's/[email protected][.a-z0-9]*//g' 
[email protected] [email protected] 

sed命令將刪除所有您不想要的字符串。

您不能直接使用grep,因爲grep按行工作。 -o標誌爲grep允許您獲取每個匹配的單詞,但-v標誌(否定匹配)僅適用於整條線。如果你想這樣做,你將不得不要求grep進行所有匹配(除非你使用Perl正則表達式作爲GNU擴展到grep)。

或者,你可以分解爲grep INTE幾行輸出,並做到這一點,而不是這樣:

$ echo "[email protected] [email protected] [email protected] [email protected]" | tr ' ' '\n' | grep -v '1280' 
[email protected] 
[email protected]