Friday, 15 February 2013

regex - Extracting data between keywords into an array using perl -



regex - Extracting data between keywords into an array using perl -

i have file has keywords frame 1, frame 2 , frame 3 ... frame 100+, want extract info between each frames , place in array. tried , not getting per need. maintain getting matched line. tried 2 ways.

my $key1 = "frame 1" ; $key2 = "frame 2"; while (<readhandle>){ if (/^$key1/../^$key2/){ @linearray=$_; print "\n @linearray \n" ; } }

this print lines. , sec seek follows

my $key1 = "frame" ; while (<readhandle>){ if (/^$key1/){ @linearray=$_; print "\n @linearray \n" ; } }

this print matched lines not info between.

my file looks below

frame 1: 140 bytes on wire (1120 bits), 140 bytes captured (1120 bits) encapsulation type: ethernet (1) arrival time: jun 11, 2014 16:03:37.864278820 republic of india standard time ethernet ii, src: cisco_a9:94:0a (00:30:96:a9:94:0a), dst: ipv6mcast_00:00:00:0d (33:33:00:00:00:0d) frame 2: 90 bytes on wire (720 bits), 90 bytes captured (720 bits) encapsulation type: ethernet (1) net protocol version 6, src: ::200:1:1:2 (::200:1:1:2), dst: ff02::1:ff01:1 (ff02::1:ff01:1) 0110 .... = version: 6

so on.. help or suggestion much appreciated.

you can utilize array of array,

my @linearray; while (<readhandle>){ force @linearray, [] if /^frame/; force @{ $linearray[-1] }, $_ if @linearray; } utilize data::dumper; print dumper \@linearray;

regex perl search data-structures

No comments:

Post a Comment