For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > May 2007 > applying a regular expression on the continuous output of ping command









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author applying a regular expression on the continuous output of ping command
Srinivas

2007-05-16, 7:58 am

Hi,

ping gcrossing.net|perl -le "m/time=(\d+)/;print $1";

Can some one help me with the above command

-srini
Chas Owens

2007-05-16, 7:58 am

On 5/16/07, Srinivainputs <srini@gcrossing.net> wrote:
> Hi,
>
> ping gcrossing.net|perl -le "m/time=(\d+)/;print $1";
>
> Can some one help me with the above command


Add an n to the perl arguments to get it loop over stdin and use
single quotes to prevent shell from trying to interpolate $1.

ping gcrossing.net|perl -nle 'm/time=(\d+)/;print $1';

Also, you should probably write it like this:

ping gcrossing.net|perl -nle 'print /time=([\d.]+)/ ? $1 : "time not found"';

or this

ping gcrossing.net|perl -nle 'print $1 if /time=([\d.]+)/';
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com