Perl: How to identify a line with hex fields in it

ambuli
ambuli used Ask the Experts™
on
Hi there,

I have a file with some lines printed in the following way.This is a timestamp

a name           at 71050.762 s [04562b0c]

I have to find this lines and then extract the time value, i.e 71050.762 s in this example.  Please note that spaces as in the line.

Thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2014
Top Expert 2015
Commented:
while( <> ){
   $time=$1 if /([\d.]+) s \[\w+\]/;
}

Author

Commented:
Thanks Ozo,

How can I check if a particular line is in this form before extracting the time.

Author

Commented:
sorry! I think your code does it.
Thanks.
ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
 $time=$1 if /([\d.]+) s \[\w+\]/;
will check if a line is in the form  /([\d.]+) s \[\w+\] before extracting the time.
If you want to be more specific you might use
  $time=$1 if /^a name           at ([\d.]+) s \[04562b0c\]$/;

Author

Commented:
Thank you

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial