I’m trying to extract the time from a string using bash, and I’m having a hard time figuring it out.
My string is like this:
US/Central - 10:26 PM (CST)
And I want to extract the 10:26 part.
Anybody knows of a way of doing this only with bash – without using sed, awk, etc?
Like, in PHP I would use – not the best way, but it works – something like:
preg_match( ""(\d{2}\:\d{2}) PM \(CST\)"", "US/Central - 10:26 PM (CST)", $matches );
Thanks for any help, even if the answer uses sed or awk
Using pure bash :
another solution with bash regex :
another solution using
grepand look-around advanced regex :another solution using sed :
another solution using perl :
and last one using awk :