in reply to Finding specific keyword in Perl

One possibility: count how many Static's you have seen. After the second one, capture all the IPs. You might need another flag to signal you are entering a new record for which you no longer want to capture them.
#!/usr/bin/perl use warnings; use strict; my $static = 0; my @IPs; while (<DATA>) { push @IPs, $1 if /([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) +/ and $static == 2; $static++ if /Static/; }

Replies are listed 'Best First'.
Re^2: Finding specific keyword in Perl
by zakishah (Novice) on Aug 21, 2012 at 14:55 UTC

    Thank you very much it really works but the problem is it is printing the ip's uptill the time the file is open. i need it to display ips only once which appears after second static. i dont want them to print multiple times