maheshkumar has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Writing a new file in Perl
by zwon (Abbot) on Jul 05, 2012 at 11:12 UTC | |
|
Re: Writing a new file in Perl
by aaron_baugher (Curate) on Jul 05, 2012 at 13:00 UTC | |
by maheshkumar (Sexton) on Jul 07, 2012 at 20:36 UTC | |
by aaron_baugher (Curate) on Jul 07, 2012 at 22:35 UTC | |
|
Re: Writing a new file in Perl
by daxim (Curate) on Jul 05, 2012 at 11:09 UTC | |
by maheshkumar (Sexton) on Jul 05, 2012 at 11:44 UTC | |
by maheshkumar (Sexton) on Jul 11, 2012 at 11:31 UTC | |
by daxim (Curate) on Jul 11, 2012 at 14:41 UTC | |
by maheshkumar (Sexton) on Jul 11, 2012 at 15:05 UTC | |
by Anonymous Monk on Jul 05, 2012 at 11:48 UTC | |
by daxim (Curate) on Jul 11, 2012 at 14:40 UTC |