LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

Awk line to convert [HH]:MM:SS to seconds

Posted 08-17-2015 at 06:35 PM by the dsc

awk -F':' '{if (NF == 2) {print $1 * 60 + $2} else {print $1 * 60 * 60 + $2 * 60 + $3}}'

I saw it somewhere and maybe tweaked a bit, maybe not -- I barely know anything of awk.

I find it particularly good because you can give just minutes or hours and minutes as input, there's no mandatory hours, unlike some other answers you'll see if you google for it, which will assume minutes as hours if there is no hours.

Of course, such assumption of the leading number as hours may be exactly what one may need, but if that's not the case, then this is quite handy.
Posted in Uncategorized
Views 561 Comments 2
« Prev     Main     Next »
Total Comments 2

Comments

  1. Old Comment
    so what if the input does not have seconds?
    Posted 08-24-2015 at 07:01 AM by Skaperen Skaperen is offline
  2. Old Comment
    Quote:
    Originally Posted by Skaperen View Comment
    so what if the input does not have seconds?
    Funnily enough, if it's just a single number without ":", it takes it as hours.

    The input can have no seconds as long as it's at least "[M]M:[0]0" -- or even just "M:".
    Posted 08-30-2015 at 03:00 PM by the dsc the dsc is offline
    Updated 08-30-2015 at 03:30 PM by the dsc
 

  



All times are GMT -5. The time now is 10:33 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration