Hi, I have a text file with information containing computer ip addresses, mac addresses, os details etc that looks like this for each node:
Nmap scan report for somenode.somedomain.com (192.x.x.x)
Host is up (0.032s latency).
Not shown: 974 closed ports
PORT STATE SERVICE
53/tcp open domain
...
49160/tcp open unknown
MAC Address: 24:34:E4:57:aB:BC (some company)
Device type: general purpose
Running: Microsoft Windows 7|2008
OS CPE: cpe:/o:microsoft:windows_7::-
cpe:/o:microsoft:windows_7::sp1
cpe:/o:microsoft:windows_server_2008::sp1
cpe:/o:microsoft:windows_8
OS details: Microsoft Windows 7 SP0 - SP1, Windows Server 2008 SP1, or Windows 8
Network Distance: 1 hop

I want to get the information reorganised so it looks like this:

$IPADDRESS, $MACADDRESS, $OSCPE, $OSDETAILS
$IPADDRESS, $MACADDRESS, $OSCPE, $OSDETAILS
etc
I slurped a file and tried to get this done various ways - one of which is

<code>($IPADDR,$MACADDR,$OS,$OSDETL) = $TEXT =~ /(192\.168\.1\.\d+).*?(\d2:\d2:\d2:\d2:\d2:\d2)/g;<code>

but it doesn't work. It will work if I only use

<code> @matches = ( $TEXT =~ /(192\.168\.1\.\d+)/g);
foreach my $val (@matches) {
print "$val\n";
<code>

But if I try to match another string in the same regular expression it fails. For example, this doesn't work:

<code> @matches = ( $TEXT =~ /(192\.168\.1\.\d+).*?(\d2:\d2:\d2:\d2:\d2:\d2)/g);
<code>


Thanks


In reply to Slurping file using regular expressions for array or variables by firefli

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.