I am writing a code which can extract the IPs from a specific text file and make it into one separate text file. So far I am trying to do the following

use Regexp::Common qw/net/; system("clear"); my $file_content = ""; my $parsed = ""; open(INPUT,"<Samplle_2.txt") or die "cannot open Google.txt : $!"; while(<INPUT>){ my $line = $_; chomp($line); $file_content .= $line; } $_ = "\n $file_content"; while(/hops(.+)Trace/mg){ print $1, "\n" if /($RE{net}{IPv4})/; open FILE, ">Google_1" or die $!; print FILE "Important Information \n $1"; close FILE; }

The new file just gives me the first IP mentioned in the file, any idea about this?

My file format looks something like the following

;ANSWER 1.chstatic.cvcdn.com. 2699 IN CNAME d2cc2sq9kkgwfv.cloudfront.net. d2cc2sq9kkgwfv.cloudfront.net. 37 IN CNAME d2cc2sq9kkgwfv.lhr5.cloudfr +ont.net. d2cc2sq9kkgwfv.lhr5.cloudfront.net. 37 IN A 54.240.166.179 d2cc2sq9kkgwfv.lhr5.cloudfront.net. 37 IN A 54.240.166.100 d2cc2sq9kkgwfv.lhr5.cloudfront.net. 37 IN A 54.240.166.189 d2cc2sq9kkgwfv.lhr5.cloudfront.net. 37 IN A 54.240.166.183 d2cc2sq9kkgwfv.lhr5.cloudfront.net. 37 IN A 54.240.166.77 d2cc2sq9kkgwfv.lhr5.cloudfront.net. 37 IN A 54.240.166.209 d2cc2sq9kkgwfv.lhr5.cloudfront.net. 37 IN A 54.240.166.186 d2cc2sq9kkgwfv.lhr5.cloudfront.net. 37 IN A 54.240.166.123 ;AUTHORITY ;ADDITIONAL Traceroute: 10 1339258888 1339258869 1339258869 LocalDNS LocalDNS 10.7 +1.165.25 Tracing route to 10.71.165.25 over a maximum of 20 hops 1 139 ms 89 ms 114 ms 10.94.1.6 2 134 ms 129 ms 99 ms 10.130.100.1 3 119 ms 129 ms 109 ms 10.130.100.177 4 113 ms 119 ms 90 ms 10.71.165.25 Trace complete. Query: 23 1339258888 LocalDNS 1.chstatic.cvcdn.com 1 True 0.2893088367 +38 0.326385895414 id 34054 opcode QUERY rcode NOERROR flags QR RD RA ;QUESTION

And i just need the IPs from line 1, 2, 3, 4 and don't want the IPs that are above.... Any thought on this


In reply to Writing a new file in Perl by maheshkumar

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.