LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 05-30-2015, 12:39 PM   #1
deepGC
LQ Newbie
 
Registered: May 2015
Posts: 21

Rep: Reputation: Disabled
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?
 
Old 05-30-2015, 01:06 PM   #2
deepGC
LQ Newbie
 
Registered: May 2015
Posts: 21

Original Poster
Rep: Reputation: Disabled
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
 
Old 05-30-2015, 01:07 PM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
??? just convert everything to a minute (add 1 for any seconds), mod 15. add 1 for any nonzero remainder.
 
Old 05-30-2015, 01:09 PM   #4
deepGC
LQ Newbie
 
Registered: May 2015
Posts: 21

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
??? 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)}'
 
Old 05-30-2015, 01:09 PM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Quote:
Originally Posted by deepGC View Post
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 01:13 PM.
 
Old 05-30-2015, 01:13 PM   #6
deepGC
LQ Newbie
 
Registered: May 2015
Posts: 21

Original Poster
Rep: Reputation: Disabled
Thanks, that works a treat now
 
Old 05-30-2015, 01:21 PM   #7
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,493

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635
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.
Old 05-30-2015, 02:03 PM   #8
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,028

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
Quote:
Originally Posted by jlinkels View Post
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.
Old 05-30-2015, 03:14 PM   #9
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,493

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635
Quote:
Originally Posted by schneidz View Post
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.

jlinkels
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Q: Modifying the date/time stamp of messages from syslog "classic"... doable? rnturn Linux - Software 3 07-22-2014 05:21 PM
id "2", "3", "4", "5"respawning too fast: disabled for 5 minutes cesarff2000 Linux - Newbie 3 06-27-2012 11:50 PM
"How to rename files with current date stamp appended into name using shell script?" nandi Linux - Newbie 4 10-05-2011 11:36 AM
Execution of a script to be stopped after "x" minutes of time YSE Linux - Newbie 3 10-01-2008 01:00 AM
execute a script every 5 minutes "cron" ALInux Linux - General 1 02-10-2006 03:36 AM


All times are GMT -5. The time now is 02:18 AM.

Main Menu
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