On Mon, Aug 3, 2009 at 4:00 PM, John W. Krahn <[email protected]> wrote:
> jet speed wrote:
>
>> Guys,
>>
>
> Hello,
>
> I am new to perl, I am having trouble capturing the required output from
>> the command, with my limited knowlege i tried to put something togather.
>> not
>> sure how to proceed beyond.
>>
>
> In a regular expression, when you want to capture part of a pattern you
> have to enclose that part in parentheses.
>
>
> What i am trying to achieve
>> for certain drives ex : B3494_901, B3494_102 from the outputlist is to
>> find
>> the index number ex: 19 for drive B3494_102 as in the output below
>> then collect the different index number for these selected drives in a
>> variable $idx = 1:2:19:5
>> then i can use the $idx inside the command 'tpconfig -multiple_delete
>> -drive $idx '
>>
>> Any help would be much appericiated.
>>
>> Script
>>
>> use strict;
>> use warnings;
>>
>> my @tpd = `tpconfig -dl`;
>> my $idx;
>> my $drv;
>>
>> foreach my $line (@tpd) {
>> chomp $line;
>> #$line =~ m/^Index\s+\d\d/ && do {
>> $line =~ m/^Index\w+/ && do {
>>
>
> It looks like the pattern you want is more like:
>
> $line =~ /
> ^ # start of string
> \s+ # followed by whitespace
> Index # match literal string
> \s+ # followed by whitespace
> ( \d+ ) # match and capture any numerical digits
> /x
>
>
> $idx = $1;
>> print "$idx \n";
>> };
>> $line =~ /^Drive.*\s+\w\d+/ && do {
>>
>
> $line =~ /
> ^ # start of string
> \s+ # followed by whitespace
> Drive\ Name # match literal string
> \s+ # followed by whitespace
> ( \w+ ) # match and capture any word characters
> /x
>
>
> $drv =$1;
>> print "$drv /n";
>> };
>>
>> }
>>
>>
>> ( tpconfig -dl )command output below
>>
>>
>>
>> Drive Name B3494_102
>> Index 19
>> NonRewindDrivePath /dev/rmt/23cbn
>> Type hcart2
>> Status DOWN
>> SCSI Protection SR (Global)
>> Shared Access Yes
>> TLH(0) IBM Device Number=974680
>> Serial Number 000007897468
>>
>> Different Drives
>>
>> Drive Name B3494_901
>> Drive Name B3494_100
>> Drive Name B3494_102
>>
>
>
> John
> --
> Those people who think they know everything are a great
> annoyance to those of us who do. -- Isaac Asimov
>
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
>
Hi John, Thanks for your help, Much appreciated. Please could you also
refer any good reference for Regular expression for a beginer like me, would
be great.
Cheers, Sj