Compare fraction number and convert duration to seconds


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare fraction number and convert duration to seconds
# 1  
Old 01-14-2014
Compare fraction number and convert duration to seconds

Hi friends,

I have a file with contents below:

Code:
01.m4a  00:14:45.82, 01.mp4 00:03:46.05, -659.770000
05.m4a  00:27:43.51, 05.mp4 00:27:45.10, 1.590000
06.m4a  00:11:39.73, 06.mp4 00:11:44.60, 4.870000

If 5th column value more than 3 or less than -3 then I should get its name (from first column) without file extension and value of 2nd column in seconds (2nd column is specified in terms of hh:mm:ss)
output:
Code:
01:885
06:699

Please advise, thanks!

Last edited by magnus29; 01-14-2014 at 05:08 PM..
# 2  
Old 01-14-2014
Try
Code:
 awk '$5^2>9{split ($2, T, "[:.]"); sub (/\..*$/,"",$1);print $1":"T[1]*3600+T[2]*60+T[3]}' file
01:885
02:1288
03:824
04:1227
06:699

This User Gave Thanks to RudiC For This Post:
# 3  
Old 01-14-2014
Brilliant! Worked like charm!!

Many thanks RudiC Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Mp3 duration rounded up to nearest seconds

Hi, can anyone provide more details to why an audio file's duration is seen as 10 seconds on unix and 9 seconds on windows Read about windows MFT rounding down to nearest seconds, is there any article on unix rounding up? thanks in advance (1 Reply)
Discussion started by: wsps1750
1 Replies

2. UNIX for Beginners Questions & Answers

How to convert days hours minutes seconds to minutes?

Hi, please help with below time conversion to minutes. one column values: 2 minutes 16 seconds 420 msec 43 seconds 750 msec 0 days 3 hours 29 minutes 58 seconds 480 msec 11 seconds 150 msec I need output in minutes(total elapsed time in minutes) (2 Replies)
Discussion started by: ramu.badugula
2 Replies

3. Shell Programming and Scripting

Convert a future date into epoch seconds on HPUX system

Hi All, I have scenario where i have to compare two dates. I thought of converting them to epoch seconds and do a numeric comparison. This works fine on Linux systems. $ date -d '2015/12/31' +%s 1451538000 $ date +%s 1449159121 But we don't have -d option in HPUX. What would be... (5 Replies)
Discussion started by: veeresh_15
5 Replies

4. Shell Programming and Scripting

Convert Date from File and Calculate Duration

Hi - I am looking for a little help to read in 2 date fields from a file in format: 20120508134012.3 yyyymmddhhmmss.tenths of a second So i want to: 1. Read in the 1st date from the file 2. Read in the second date from the file 3. Calculate the difference in minutes (or seconds) 4. ... (5 Replies)
Discussion started by: Newbie2012
5 Replies

5. Shell Programming and Scripting

Convert duration of the process to seconds

Hi, I am looking to write a script to kill the process which are running for more than 7 days. So i have a command like "ps -eo pid,etime,args | grep -i xxxx" ( process which has xxx in it and running for more than 7 days needs to be killed ). When i exeucte the above command , i am... (2 Replies)
Discussion started by: forums123456
2 Replies

6. Shell Programming and Scripting

Script to add time convert to seconds

Hi, What i am looking for and i am new to this too, is a bash script that will add time in the format hh:mm:ss and produce the answer in minutes or seconds. It needs to be a loop since there are hundreds of times in my file. This is data is from a CDR that calculates duration of time used. ... (2 Replies)
Discussion started by: trotella
2 Replies

7. UNIX for Dummies Questions & Answers

Number of leap seconds

Is there a function call in std library or unit command that returns the number of current leap seconds? GG (4 Replies)
Discussion started by: NAVTime
4 Replies

8. Shell Programming and Scripting

Convert Seconds to hh:mm:ss

Hi All I need to convert a number of fields in a record from seconds to hh:mm:ss ( or possibly hhh:mm:ss ). I'm guessing awk is the way to go . File has multiple records and each record contains 101 fields - can awk handle that ? The seconds values will be in fields 3 - 101 and could be 0. ... (4 Replies)
Discussion started by: Mudshark
4 Replies

9. Shell Programming and Scripting

awk convert seconds to time of day

Does anyone know of a way to convert "seconds" to time of day in "hh:mm:ss" ? Trying to do in awk with strftime but with no luck. Thanks (2 Replies)
Discussion started by: timj123
2 Replies

10. UNIX for Advanced & Expert Users

how to get number of seconds

How do I get the number of seconds since 1970, within a script, for the previous day at 23:59? I need this value to pass into a sql statement to cleanup records older than the previous day at midnight. It will be automated via cron so no hard coding allowed. Thanks! (2 Replies)
Discussion started by: captainzeb
2 Replies
Login or Register to Ask a Question