grep 搜尋不包含關鍵字的行

2021-07-24 03:44:57 字數 3480 閱讀 7172

grep -v down-v 是不顯示匹配上的內容,顯示不包含down的內容。

dotheright@dotheright

:~$ nmap -v -sn 192.168.1.1/24

dotheright@dotheright:~$ nmap -v -sn 192.168.1.1/24

nmap scan report for 192.168.1.0 [host down]

nmap scan report for 192.168.1.1 host is up (0.0021s latency).

nmap scan report for 192.168.1.2 [host down]

nmap scan report for 192.168.1.3 [host down]

…… nmap scan report for 192.168.1.98 [host down]

nmap scan report for 192.168.1.99 [host down]

nmap scan report for 192.168.1.100 host is up (0.084s latency).

nmap scan report for 192.168.1.101 [host down]

nmap scan report for 192.168.1.102 host is up (0.062s latency).

nmap scan report for 192.168.1.103 host is up (0.0060s latency).

nmap scan report for 192.168.1.104 [host down]

nmap scan report for 192.168.1.105 host is up (0.10s latency).

nmap scan report for 192.168.1.106 host is up (0.00092s latency).

nmap scan report for 192.168.1.107 [host down]

nmap scan report for 192.168.1.108 [host down]

…….

nmap scan report for 192.168.1.254 [host down]

nmap scan report for 192.168.1.255 [host down]

read data files from: /usr/bin/../share/nmap

nmap done: 256 ip addresses (6 hosts up) scanned in 4.28 seconds

如果只是顯示up的行,沒有想要的ip 位址

dotheright@dotheright

:~$ nmap -v -sn 192.168.1.1/24 | grep up

dotheright@dotheright:~$ nmap -v -sn 192.168.1.1/24 | grep up

host is up (0.0034s latency).

host is up (0.021s latency).

host is up (0.16s latency).

host is up (0.012s latency).

host is up (0.035s latency).

host is up (0.0056s latency).

host is up (0.0012s latency).

nmap done: 256 ip addresses (7 hosts up) scanned in 3.63 seconds

所以過濾掉down是個不錯的選擇,-v 是不顯示匹配上的內容

dotheright@dotheright

:~$ nmap -v -sn 192.168.1.1/24 | grep -v down

dotheright@dotheright:~$ nmap -v -sn 192.168.1.1/24 | grep -v down

starting nmap 7.01 ( ) at 2016-10-28 00:57 cst

initiating ping scan at 00:57

nmap scan report for 192.168.1.1

host is up (0.0039s latency).

nmap scan report for 192.168.1.100

host is up (0.014s latency).

nmap scan report for 192.168.1.101

host is up (0.061s latency).

nmap scan report for 192.168.1.103

host is up (0.013s latency).

nmap scan report for 192.168.1.105

host is up (0.0090s latency).

nmap scan report for 192.168.1.106

host is up (0.000086s latency).

read data files from: /usr/bin/../share/nmap

nmap done: 256 ip addresses (6 hosts up) scanned in 2.96 seconds

趨於完美,但是還是有很多無用資訊,進一步過濾.

dotheright@dotheright

:~$ nmap -v -sn 192.168.1.1/24 | grep -v down | grep 192

dotheright@dotheright:~$ nmap -v -sn 192.168.1.1/24 | grep -v down | grep 192

nmap scan report for 192.168.1.1

nmap scan report for 192.168.1.100

nmap scan report for 192.168.1.101

nmap scan report for 192.168.1.103

nmap scan report for 192.168.1.104

nmap scan report for 192.168.1.105

nmap scan report for 192.168.1.106

grep 基於關鍵字搜尋

grep linux etc passwd 搜尋passwd檔案下的包含linux的行 find user linux grep video 在使用者為linux的根目錄下搜房video內容 netstat tnpl grep server 查詢網路程序為server的資料 i在搜尋的時候忽略大小寫...

Linux下grep查詢包含某個關鍵字的上下文資訊

標準unix linux下的grep通過以下引數控制上下文 grep c 5 foo file 顯示file檔案中匹配foo字串那行以及上下5行 grep b 5 foo file 顯示foo及前5行 grep a 5 foo file 顯示foo及後5行 如果想要把這些內容匯入到乙個指定的檔案可以...

關鍵字搜尋

關鍵字搜尋 function sercah waitmsg 已找到對應的 g keys count 處關鍵字!1 相同關鍵字查詢時返回 reading children reading box m p css span keys removeattr style removeattr id g ke...