2013-06-24 32 views
1

我正在解析ps -ef | grep進程中的一些信息,但它總是在grep的輸出中顯示grep本身的最後一行。 如何在沒有最後一行的情況下獲得grep的輸出? 輸出看起來像這樣:BASH:如何避免在grep中顯示最後一行?

[email protected]:~# ps -ef |grep gnome-terminal 
itaig  3307 2306 0 09:37 ?  00:00:00 /bin/sh -c gnome-terminal 
itaig  3308 3307 0 09:37 ?  00:01:58 gnome-terminal 
root  7055 5047 0 13:37 pts/10 00:00:00 grep --color=auto gnome-terminal 
[email protected]:~# 

回答

1

你可以做兩件事情:

grep的exluding的grep本身:

ps -ef |grep gnome-terminal | grep -v grep 

或添加字符串cond ition與此不匹配grepsee explanation):

ps -ef |grep [g]nome-terminal 
+1

爲什麼我沒有考慮它? grep -v grep就足夠了!謝謝 –

2

嘗試搜索一些東西,不會在grep命令行匹配:

ps -ef | grep [g]nome-terminal 
相關問題