Hi Jet Speed,

On Tue, 13 Nov 2012 11:44:26 +0000
jet speed <speedj...@googlemail.com> wrote:

> Hi All,
> 
> I have a file with similar data, around 10,000 entries with similar format.
> 
> i need to extract the output in below format. I can match the WWN and push
> into an arrray, however i am not sure how to reference the WWN   to its
> corresponding device displayDevNum as in the below format.
> Any help would be much appreciated.
> 

You can keep the displayDevNum in a variable global to the loop. Like this:

#!/usr/bin/perl

use strict;
use warnings;

my $last_dev_num;

while (my $line = <>)
{
    chomp($line);
    if (my ($dev_num) = $line =~ /\AdisplayDevNum=(.*)\z/)
    {
        $last_dev_num = $dev_num;
    }
    elsif (my ($wwn) = $line =~ /\AWWN=(.*)\z/)
    {
        print "$last_dev_num $wwn\n";
    }
}

Regards,

        Shlomi Fish

> I am using test data here due to system restrictions.
> 
> 
> required output
> ------------------------
> 10:79 10.00.00.00.00.C0.43.33.AB
> 10:79 10.00.00.00.00.C0.43.33.A2
> 10:99 10.00.00.00.00.C0.22.33.56
> 10:99 10.00.00.00.00.C0.34.33.A0
> 10:99 10.00.00.00.00.C0.22:49:33
> 10.55 10.00.00.00.00.C9.43.42.B6
> 10.55 10.00.00.00.00.C0.43.23.C9
> 
> DATA - file.txt
> --------------------
> devNum=4,177
> displayDevNum=10:79
> LUN=121
> WWN=10.00.00.00.00.C0.43.33.AB
> nickname=a5
> WWN=10.00.00.00.00.C0.43.33.A2
> nickname=wacke22
> devNum=4,177
> displayDevNum=10:99
> LUN=121
> WWN=10.00.00.00.00.C0.22.33.56
> nickname=a2
> WWN=10.00.00.00.00.C0.34.33.A0
> nickname=ajx
> WWN=10.00.00.00.00.C0.22:49:33
> nickname=yah1
> devNum=4,177
> displayDevNum=10:55
> LUN=121
> WWN=10.00.00.00.00.C9.43.42.B6
> nickname=a52
> WWN=10.00.00.00.00.C0.43.23.C9
> nickname=wack1
> 
> 
> Thanks
> Sj



-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Interview with Ben Collins-Sussman - http://shlom.in/sussman

Chuck Norris is not afraid of superstitions. Superstitions are afraid of Chuck
Norris. (via Dov Levenglick)

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to