Skip to content
Advertisement

Grepping Numbers With Decimal Places

I’m trying to figure out how to grep a time stamp read from a file that consists of a number with a decimal, but I can’t seem to get the output I’m looking for, any help would be great! Thanks in advance.

Example:

[Time since reference or first frame: 691.933275000 seconds]
[Time since reference or first frame: 691.953127000 seconds]
[Time since reference or first frame: 691.992275000 seconds]
[Time since reference or first frame: 691.997590000 seconds]

The result should be:

691.933275000
691.953127000
691.992275000
691.997590000

What I’ve Tried:

grep '[0-9].[0-9]' tmp.txt
grep -Eo '[0-9].[0-9]' tmp.txt
grep -Eo '([0-9]{1,10}[.]){1,10}[0-9]' tmp.txt

Advertisement

Answer

you can use awk to split the file to retrieve those fields which has decimal number

cat file_name | awk '{print $7}'
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement