0

I need to parse a file like this:

Nmap scan report for pc15393.foster.xxx.com (192.168.2.211)
Nmap scan report for lab-776.foster.xxx.com (192.168.2.212)
Nmap scan report for 78T458Y.foster.xxx.com (192.168.2.213)

I'd like to get rid of "Nmap scan report for" and get the following:

pc15393.foster.xxx.com (192.168.2.211)
lab-776.foster.xxx.com (192.168.2.212)
78T458Y.foster.xxx.com (192.168.2.213)

If I use the following regex: extract = re.findall (r'for.*',line) I get everything starting from "for" but that's wrong. Can anyone help me? Thanks a lot Knud

knud
  • 1

2 Answers2

0

Here you go. Clearly replace my_file.txt with your file. This was python 2.7.12

#/usr/bin/env python
import re
pattern = re.compile("Nmap scan report for (.*)")
for i, line in enumerate(open('my_file.txt')):
    for match in re.finditer(pattern, line):
        print match.group(1)
Sirch
  • 5,815
0

If you want to get only this data, better use awk.

cat yourfile | awk '{print $5 $6}'

If give information you want.