-2

I have this bit of info from a bash script. How can I keep only the time?

"real\t0m3.21s"

Needs to be

3.21s 

The output is produced from time function.

Stat.Enthus
  • 307
  • 1
  • 7
  • What if the output is `2m3.21s` -- you don't care about the 2 minutes? – Barmar Mar 30 '21 at 08:10
  • See https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html#Shell-Parameter-Expansion for the parameter expansion operators you can use to remove `real\t*m` from the beginning of the string. – Barmar Mar 30 '21 at 08:11
  • 1
    StackOverflow is not a free coding service. You're expected to [try to solve the problem first](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users). Please update your question to show what you have already tried in a [mcve]. For further information, please see [ask], and take the [tour] :) – Barmar Mar 30 '21 at 08:12

1 Answers1

0

Using sed:

sed -n 's/real\\t0m//p' <<< "real\t0m3.21s"

Replace "read\t0m" for nothing and print

Raman Sailopal
  • 11,713
  • 2
  • 8
  • 16