我希望有一個正則表達式下面輸入grep的非匹配端口號@服務器
echo "[email protected] [email protected] [email protected] [email protected]"| grep -Po 'regexp'
我想輸出不包含1280字,如下
[email protected] [email protected]
我希望有一個正則表達式下面輸入grep的非匹配端口號@服務器
echo "[email protected] [email protected] [email protected] [email protected]"| grep -Po 'regexp'
我想輸出不包含1280字,如下
[email protected] [email protected]
您可以使用此前瞻和回顧後發正則表達式:
echo "[email protected] [email protected] [email protected] [email protected]"| grep -Po '(?<=\s|^)(?!\S*1280)\S+'
[email protected]
[email protected]
(?<=\s|^)
斷言還有我們的比賽(?!\S*1280)
前的空格或行開始斷言,沒有在字管的結果,如果你想從這個輸出中刪除換行符tr '\n' ' '
沒有1280
。
$ 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]
您可以使用sed
和grep
,讓您所需的輸出。
代碼
echo "[email protected] [email protected] [email protected] [email protected]"| sed 's/[email protected][0-9,a-z,A-Z,.]\+//g' | grep -Po '\[email protected][A-Z,a-z,0-9,\.]+'
希望這會爲你工作。
你問題不清楚。請更正確地解釋它 – Arijit
是否要空格分隔單詞,然後返回每個不包含1280的單詞? – AbhiNickz
'perl -E'@ a = split/\ s + /,q {1280 @ lic1 1728 @ lic1 [email protected] 1924 @ lic1};對於grep!/ 1280 /,@ a'' – stevieb