1

I'm receiving an uptime in this format:

167h58m10.586582048s

I want to transform it to seconds and discard the fraction part. I know awk could do that if only the received string had the same separator. That's not the case.

How could I convert that to seconds?

2
  • I'm not sure what you mean by "only the received string had the same separator" - POSIX awk should permit an extended regular expression field separator such as [hm.] I think? Commented Feb 3, 2022 at 1:45
  • 1
    Read man date.
    – waltinator
    Commented Feb 3, 2022 at 1:53

1 Answer 1

2

If I try this:

$ echo "167h58m10.586582048s" | awk -F '[hm.]' '{ print ($1 * 3600) + ($2 * 60) + $3 }'
604690

It works great.

Thanks @steeldriver. I didn't know about that.

I found this good article about Field Separators in awk.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .