in reply to Re: Parsing/Splitting data
in thread Parsing/Splitting data

Thanks for quick response, here is the response:
$VAR1 = [ '< ', ' ', ' EQUIP-OME1 15-08-26 15:19:13 ', 'M CTAG COMPLD ', ' "OC192-1-1-2,OC192:OPR-OCH,-10.20,COMPL,NEND,RCV,1-DAY,0 +8-25,00-00,1,,,," ', ' "OC192-1-1-2,OC192:OPT-OCH,-3.50,COMPL,NEND,TRMT,1-DAY,0 +8-25,00-00,1,,,," ', '> ', ' ', ' 123-EQUIP-OME2 15-08-26 15:19:25 ', 'M CTAG COMPLD ', ' "OC12-1-3-7,OC12:OPRN-OCH,-89,COMPL,NEND,RCV,1-DAY,08-25 +,00-00,1,,,," ', ' "OC12-1-3-7,OC12:OPTN-OCH,0,ADJ,NEND,TRMT,1-DAY,08-25,00 +-00,1,,,," ', '> ', ' ', ' 115-EQUIP-OME5 15-08-26 15:19:26 ', 'M CTAG COMPLD ', ' "OC12-1-4-7,OC12:OPRN-OCH,-79,COMPL,NEND,RCV,1-DAY,08-25 +,00-00,1,,,," ', ' "OC12-1-4-7,OC12:OPTN-OCH,0,ADJ,NEND,TRMT,1-DAY,08-25,00 +-00,1,,,," ', ' "OC12-1-4-8,OC12:OPR-OCH,-14.04,COMPL,NEND,RCV,1-DAY,08- +25,00-00,1,,,," ', '> ', ' ', ' EQUIP-OME8 15-08-26 15:19:27 ', 'M CTAG COMPLD ', ' "ETH10G-1-13-2,ETH10G:OPT-OCH,-3.20,COMPL,NEND,TRMT,1-DA +Y,08-25,00-00,1,,,," ', ' "ETH10G-1-13-2,ETH10G:OPRN-OCH,-17,COMPL,NEND,RCV,1-DAY, +08-25,00-00,1,,,," ', '; ' ];

Replies are listed 'Best First'.
Re^3: Parsing/Splitting data
by stevieb (Canon) on Aug 26, 2015 at 16:14 UTC

    Remove the join statement, then I think this does what you're after:

    my %data; my $device; for (@check){ next if ! /\d{1,2}-\d{1,2}/; chomp; s/\s+//g; if (/EQUIP-OME/){ $device = $_; next; } push @{$data{$device}}, $_; } for my $device (keys %data){ for my $interface (@{$data{$device}}){ print "$device,$interface\n"; } }

    Output:

    EQUIP-OME815-08-2615:19:27,"ETH10G-1-13-2,ETH10G:OPT-OCH,-3.20,COMPL,N +END,TRMT,1-DAY,08-25,00-00,1,,,," EQUIP-OME815-08-2615:19:27,"ETH10G-1-13-2,ETH10G:OPRN-OCH,-17,COMPL,NE +ND,RCV,1-DAY,08-25,00-00,1,,,," 115-EQUIP-OME515-08-2615:19:26,"OC12-1-4-7,OC12:OPRN-OCH,-79,COMPL,NEN +D,RCV,1-DAY,08-25,00-00,1,,,," 115-EQUIP-OME515-08-2615:19:26,"OC12-1-4-7,OC12:OPTN-OCH,0,ADJ,NEND,TR +MT,1-DAY,08-25,00-00,1,,,," 115-EQUIP-OME515-08-2615:19:26,"OC12-1-4-8,OC12:OPR-OCH,-14.04,COMPL,N +END,RCV,1-DAY,08-25,00-00,1,,,," EQUIP-OME115-08-2615:19:13,"OC192-1-1-2,OC192:OPR-OCH,-10.20,COMPL,NEN +D,RCV,1-DAY,08-25,00-00,1,,,," EQUIP-OME115-08-2615:19:13,"OC192-1-1-2,OC192:OPT-OCH,-3.50,COMPL,NEND +,TRMT,1-DAY,08-25,00-00,1,,,," 123-EQUIP-OME215-08-2615:19:25,"OC12-1-3-7,OC12:OPRN-OCH,-89,COMPL,NEN +D,RCV,1-DAY,08-25,00-00,1,,,," 123-EQUIP-OME215-08-2615:19:25,"OC12-1-3-7,OC12:OPTN-OCH,0,ADJ,NEND,TR +MT,1-DAY,08-25,00-00,1,,,,"

    -stevieb

      Thank you for that.

      It outputs correctly, but removes spaces between Equipment name, date, and time. I tried putting a comma to separate on blank spaces, which did work, but it also placed commas the rest of the responce (if there was blank spaces).

      How can this be modified to:

      1. Find equipment: ' 115-EQUIP-OME5 15-08-26 15:19:26

      2. chomp it with comma separation

      3. push to the rest of the string without affecting other lines

      Thank you

        How can this be modified to: ...

        Do you have any idea acondor?