Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract digits with regular expression in BASH

Tags:

regex

bash

I have a script that runs a command like
$exiftool 3PDki5ZyhBgnoTEUu4JP.mov|grep -m1 Duration and depending on the files I get back results like these

Duration                        : 01:25  
Duration                        01:25  
Duration                        01.25  

I would like to be able to extract from these strings only the time, that is, 01:25 or 1.25.

like image 548
Alex Flo Avatar asked Apr 15 '26 22:04

Alex Flo


1 Answers

try this:

....|grep -o "[^ ]*$"

or this short one:

...|awk '$0=$NF'
like image 120
Kent Avatar answered Apr 17 '26 12:04

Kent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!