On Thu, Mar 8, 2012 at 11:03 AM,  <sunita.prad...@emc.com> wrote:
> Hi All
>
> I have one output of one my command like :
>
> $output = "Step 155 of 171 
> steps.....................................Executing.
>    Step 168 of 171 steps.....................................Executing.
>    Step 171 of 171 steps.....................................Executing.
>    Local:  COMMIT............................................Done.
>
>      New symdev:  2552
>      New symdev:  2553
>    Terminating the configuration change session..............Done." ;
>
> I need to get those numbers like 2552 , 2553 .
>
> I am applying following patter matching logic but it does not get me the  1st 
> number (2552) .
>
> @devs = $output =~ m/New symdev:\s*([0-9A-Fa-f]{4})/gis;
>                        print $output,"\n";
>                        print "Devices >>>> @devs <<<<<<<<<\n";
>
>
> Could you please check what is going  wrong in  the above lines ?
>

My approach would be to read it line by line with a while loop. There
may be a better way of achieving your goal.

#!/usr/bin/perl
use warnings;
use strict;

while ( <DATA> ) {
  if ( $_ =~ m/New symdev:\s+(\d+)/ ) {
    print "$1\n";
  }
}


__DATA__
my $output = "Step 155 of 171
steps.....................................Executing.
   Step 168 of 171 steps.....................................Executing.
   Step 171 of 171 steps.....................................Executing.
   Local:  COMMIT............................................Done.

     New symdev:  2552
     New symdev:  2553
   Terminating the configuration change session..............Done." ;

###OUTPUT###
2552
2553

--
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