Link to home
Start Free TrialLog in
Avatar of ambuli
ambuliFlag for United States of America

asked on

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

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.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ambuli

ASKER

Thanks Ozo,

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

ASKER

sorry! I think your code does it.
Thanks.
 $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\]$/;
Avatar of ambuli

ASKER

Thank you