I would like to capture only successful nmap scan results and exclude results that did not return useful information. I've listed my desired grep output below that I want.
I tried using (?s) to enable DOTALL to make . include line breaks so that I can match/capture across multiple lines, but the problem is that it appears to disable the use of \n which I want to use as part of my pattern.
I'm trying to use a lookahead but I know the .* is greedy and I think it's matching the longest string which is basically the entire file. I want it to use the shortest string instead.
How can I dynamically capture successful nmap scan results in the following text file using Grep's -Po regex options?
desired output:
Nmap scan report for 10.11.1.72                       
Host is up (0.028s latency).                          
                                                      
PORT    STATE SERVICE                                 
111/tcp open  rpcbind                                 
| nfs-ls: Volume /home                                
|   access: Read Lookup NoModify NoExtend NoDelete NoExecute                                                
| PERMISSION  UID   GID   SIZE  TIME                 FILENAME                                               
| drwxr-xr-x  0     0     4096  2015-09-17T13:21:59  .
| drwxr-xr-x  0     0     4096  2015-01-07T10:56:34  ..                                                     
| drwxr-xr-x  1013  1013  4096  2015-09-17T13:21:47  jenny                                                  
| drwxr-xr-x  1012  1012  4096  2015-09-17T13:21:40  joe45                                                  
| drwxr-xr-x  1011  1011  4096  2015-09-17T13:21:52  john                                                   
| drwxr-xr-x  1014  1014  4096  2019-10-27T23:48:51  marcus                                                 
| drwxr-x---  0     1010  4096  2015-01-08T16:01:31  ryuu                                                   
|_                                                    
| nfs-showmount:                                      
|_  /home 10.11.0.0/255.255.0.0                       
| nfs-statfs:                                         
|   Filesystem  1K-blocks  Used       Available  Use%  Maxfilesize  Maxlink                                 
|_  /home       7223800.0  2059608.0  4797244.0  31%   8.0T         32000
Here is my current command that I'm starting with:
grep -Poz '(?s)\d+\.\d+\.\d+\.\d+.*Nmap' test2
test2 file:
### SCAN RESULTS ###
Nmap scan report for 10.11.1.39
Host is up (0.041s latency).
PORT    STATE    SERVICE
111/tcp filtered rpcbind
Nmap scan report for 10.11.1.44
Host is up (0.043s latency).
PORT    STATE  SERVICE
111/tcp closed rpcbind
Nmap scan report for 10.11.1.50
Host is up (0.043s latency).
PORT    STATE    SERVICE
111/tcp filtered rpcbind
Nmap scan report for 10.11.1.71
Host is up (0.040s latency).
PORT    STATE  SERVICE
111/tcp closed rpcbind
Nmap scan report for 10.11.1.72
Host is up (0.040s latency).
PORT    STATE SERVICE
111/tcp open  rpcbind
| nfs-ls: Volume /home
|   access: Read Lookup NoModify NoExtend NoDelete NoExecute
| PERMISSION  UID   GID   SIZE  TIME                 FILENAME
| drwxr-xr-x  0     0     4096  2015-09-17T13:21:59  .
| drwxr-xr-x  0     0     4096  2015-01-07T10:56:34  ..
| drwxr-xr-x  1013  1013  4096  2015-09-17T13:21:47  jenny
| drwxr-xr-x  1012  1012  4096  2015-09-17T13:21:40  joe45
| drwxr-xr-x  1011  1011  4096  2015-09-17T13:21:52  john
| drwxr-xr-x  1014  1014  4096  2019-10-27T23:48:51  marcus
| drwxr-x---  0     1010  4096  2015-01-08T16:01:31  ryuu
|_
| nfs-showmount: 
|_  /home 10.11.0.0/255.255.0.0
| nfs-statfs: 
|   Filesystem  1K-blocks  Used       Available  Use%  Maxfilesize  Maxlink
|_  /home       7223800.0  2068516.0  4788336.0  31%   8.0T         32000
Nmap scan report for 10.11.1.73
Host is up (0.041s latency).
PORT    STATE    SERVICE
111/tcp filtered rpcbind
Nmap scan report for 10.11.1.75
Host is up (0.041s latency).
PORT    STATE    SERVICE
111/tcp filtered rpcbind
Nmap scan report for 10.11.1.79
Host is up (0.041s latency).
PORT    STATE    SERVICE
111/tcp filtered rpcbind
Nmap scan report for 10.11.1.101
Host is up (0.041s latency).
PORT    STATE  SERVICE
111/tcp closed rpcbind
 
    