I am trying to get versions for services in a gnmap file. A typical line looks like:

Host: 192.x.x.x ()    Ports: 21/open/tcp//ftp//HP JetDirect ftpd/, 23/open/tcp//telnet//HP JetDirect printer telnetd (No password)/, 80/open/tcp//http//HP-ChaiSOE 1.0 (HP LaserJet http config)/, 443/open/tcp//ssl|http//HP-ChaiSOE 1.0 (HP LaserJet http config)/, 515/open/tcp//printer///, 631/open/tcp//http//HP-ChaiSOE 1.0 (HP LaserJet http config)/, 7627/open/tcp//http//HP-ChaiSOE 1.0 (HP LaserJet http config)/, 9100/open/tcp/////, 14000/open/tcp//tcpwrapped///    Seq Index: 25   IP ID Seq: Incremental

I need to match specific "open" ports and print only the matching expression. I have tried:

cat file | sed -n "/ 80\/open\/tcp\/\*\/\*\/\*\/\*\//p"

I need the result to be:

80/open/tcp//http//HP-ChaiSOE 1.0 (HP LaserJet http config)/
link|improve this question
feedback

2 Answers

You can do the same using grep with the -o (--only-matching) option:

cat teste | grep -o "80\/open\/tcp\/[^,]*"
link|improve this answer
feedback

Here is one way,

sed 's|.*, 80\([^,]*\).*|80\1|' 

and, to avoid matching say '8080' here,

sed 's|.*, 80\/\([^,]*\).*|80/\1|' 

But, I think, there is a better output form of NMAP that will make your life easier.
And, you will find more exact ways for this grepable output in nmap documentation.

link|improve this answer
Actually a gnmap file is the grepable file. Grep grabs the whole line. I need only the output that I listed above. Unfortunately the command you listed does not result in printing the result I am looking for. – blanker Jun 15 '11 at 14:46
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.