Avatar of ambuli
ambuli
Flag 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.
Perl

Avatar of undefined
Last Comment
ambuli

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
ozo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ambuli

ASKER
Thanks Ozo,

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

ASKER
sorry! I think your code does it.
Thanks.
ozo

 $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\]$/;
Your help has saved me hundreds of hours of internet surfing.
fblack61
ambuli

ASKER
Thank you