System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing a file (NMAP output)

rmueller58
Valued Contributor

Parsing a file (NMAP output)

We are trying catalog our servers that have port 443 open, so we can catalog where we have used certificates.>

I have multiple files where i have entries in the files containing specific nmap output

 

Interesting ports on moodle.OURDOMAIN.TLD (XXX.YYY.ZZZ.CCCC):
PORT    STATE SERVICE
443/tcp open  https
MAC Address: AA:BB:CC:DD:EE:FF (VMWare)

Interesting ports on moodletest.OURDOMAIN.TLD (XXX.YYY.ZZZ.BBB):
PORT    STATE SERVICE
443/tcp open  https
MAC Address: AA:BB:CC:DD:EE:FF(VMWare)

Interesting ports on moodlew2.OURDOMAIN.TLD(XXX.YYY.ZZZ.AAA):
PORT    STATE SERVICE
443/tcp open  https
MAC Address: AA:BB:CC:DD:EE:FF (VMWare)

 

I would like to "grep for the word "open" and grab the two lines prior and line after the occurance of "open"


Hoping the script gurus have an idea.

1 REPLY
Dennis Handly
Acclaimed Contributor

Re: Parsing a file (NMAP output) (grep)

>I would like to "grep for the word "open" and grab the two lines prior and line after the occurrence of "open"

 

No need to script, it's built into grep:

grep -B2 -A1 open input-file