Operating System - Linux
1751894 Members
4940 Online
108783 Solutions
New Discussion

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 1
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