Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org Simple Script Needed to Calculate How Many "15" Minutes are in a Time Stamp
 Linux - Newbie This Linux forum is for members that are new to Linux. Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

 05-30-2015, 11:39 AM #1 deepGC LQ Newbie   Registered: May 2015 Posts: 21 Rep: Simple Script Needed to Calculate How Many "15" Minutes are in a Time Stamp Hello, I am performing some work on some mp3 files. One the functions requires me to know how many "15 minutes" are in a particular file. For instance, I need some code that will produce the following values from the given time stamp: 01:52:34.40 = 7 00:47:15.32 = 3 00:02:56.41 = 0 00:36:01.09 = 2 Any ideas?
 05-30-2015, 12:06 PM #2 deepGC LQ Newbie   Registered: May 2015 Posts: 21 Original Poster Rep: If I echo : \$("\$t" | awk -F: '{ print (\$1 * 60) + (\$2)}' - I get the correct number of minutes But if I try m=\$("\$t" | awk -F: '{ print (\$1 * 60) + (\$2)}') where \$t is the timestamp, I get an error message: ./processmix: line 27: 00:32:34.40: command not found
 05-30-2015, 12:07 PM #3 jpollard Senior Member   Registered: Dec 2012 Location: Washington DC area Distribution: Fedora, CentOS, Slackware Posts: 4,706 Rep: ??? just convert everything to a minute (add 1 for any seconds), mod 15. add 1 for any nonzero remainder.
05-30-2015, 12:09 PM   #4
deepGC
LQ Newbie

Registered: May 2015
Posts: 21

Original Poster
Rep:
Quote:
 Originally Posted by jpollard ??? just convert everything to a minute (add 1 for any seconds), mod 15. add 1 for any nonzero remainder.
At the current moment, I'm struggling to assign the return value from this to a variable: "\$t" | awk -F: '{ print (\$1 * 60) + (\$2)}'

05-30-2015, 12:09 PM   #5
jpollard
Senior Member

Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,706

Rep:
Quote:
 Originally Posted by deepGC If I echo : \$("\$t" | awk -F: '{ print (\$1 * 60) + (\$2)}' - I get the correct number of minutes But if I try m=\$("\$t" | awk -F: '{ print (\$1 * 60) + (\$2)}') where \$t is the timestamp, I get an error message: ./processmix: line 27: 00:32:34.40: command not found
You need the echo after the "\$(". as in \$(echo \$t | ...

I also think you need the seconds to be included - otherwise you might get some truncated video (up to a minutes worth). Oh, and include 1 any remainder from the modulus as otherwise you would loose up to 14 minutes worth.

Last edited by jpollard; 05-30-2015 at 12:13 PM.

 05-30-2015, 12:13 PM #6 deepGC LQ Newbie   Registered: May 2015 Posts: 21 Original Poster Rep: Thanks, that works a treat now
 05-30-2015, 12:21 PM #7 jlinkels Senior Member   Registered: Oct 2003 Location: Bonaire Distribution: Debian Wheezy/Jessie/Stretch/Sid, Linux Mint DE Posts: 4,613 Rep: Whenever you are working with times and involve calculation, use seconds. Code: `echo \$(date -d "1970-01-01 1:52:34" +%s) 900 / p | dc` jlinkels 1 members found this post helpful.
05-30-2015, 01:03 PM   #8
schneidz
LQ Guru

Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,145

Rep:
Quote:
 Originally Posted by jlinkels Whenever you are working with times and involve calculation, use seconds. Code: `echo \$(date -d "1970-01-01 1:52:34" +%s) 900 / p | dc` jlinkels
maybe you need -u to ignore time zones ?

1 members found this post helpful.
05-30-2015, 02:14 PM   #9
Senior Member

Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Stretch/Sid, Linux Mint DE
Posts: 4,613

Rep:
Quote:
 Originally Posted by schneidz maybe you need -u to ignore time zones ?
Yes you need that. But I wasn't aware of it as I set my system clock always to UTC.

Which is the way it should be set up IMHO. Time is time, and converting it to the local time zone should be performed in the display layer, not on the machine level. I run servers in different time zones and timestamps are a nightmare when different times are displayed.

Anyways, -u is a mandatory option if your system time isn't UTC.

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post rnturn Linux - Software 3 07-22-2014 04:21 PM cesarff2000 Linux - Newbie 3 06-27-2012 10:50 PM nandi Linux - Newbie 4 10-05-2011 10:36 AM YSE Linux - Newbie 3 10-01-2008 12:00 AM ALInux Linux - General 1 02-10-2006 02:36 AM

LinuxQuestions.org

All times are GMT -5. The time now is 09:16 AM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -