Add hh:mm:ss using awk or bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add hh:mm:ss using awk or bash
# 1  
Old 02-23-2011
Add hh:mm:ss using awk or bash

Hello,

There was a nice article here located on this forum, but I have not posted enough to add that URL.


That touched up on how to do this, but I still have not been able to figure it out. The thread is closed.

I have a file that looks like:
Code:
02/16/2011,15:23,0:00:06,4455,8883332222
02/16/2011,15:32,1:20:16,4455,8883332222
02/17/2011,11:43,0:04:22,4455,8883332222

I am trying to figure out how to add the times up in the 3rd column via bash.

I have really tried researching the forums but I have not really been able to find anything.

If anyone would have time to help me out, I would greatly appreciate it.

Thanks
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 02-23-2011 at 03:04 PM.. Reason: code tags, please!
# 2  
Old 02-23-2011
Please post a desired output given a sample input provided.
# 3  
Old 02-23-2011
Thanks vgersh99,
Below is the format that I am looking for.

01:24:44
# 4  
Old 02-23-2011
Code:
 nawk -F, '{n=split($3,a,":"); s+=(a[1]*3600+a[2]*60+a[3])}END{printf("%02d:%02d:%02d\n", s/3600,s%3600/60,s%3600%60)}' myFile

This User Gave Thanks to vgersh99 For This Post:
# 5  
Old 02-23-2011
You are the BOMB! vgersh99, it worked perfectly. Thanks again so much. I hope one day I can be half as good as you.

Regards!
# 6  
Old 02-23-2011
GREAT CHUNK OF CODE!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add another condition to bash for when not met

In the below I can not seem to add a line that will add Not low if the statement in bold is not true or meet. I guess when the first if statement is true/meet then print low, otherwise print Not low in $(NF + 1). I am not sure how to correctly add this. Thank you :). if(low <= $2 && $2 <=... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Shell Programming and Scripting

Help in awk/bash

Hi, I am also a newbie in awk and trying to find solution of my problem. I have one reference file 1.txt with 2 columns and I want to search other 10 files (a.txt, b.txt......h.txt each with 5 columns) corresponding to the values of 2nd column from 1.txt. If the value from 2nd column from 1.txt... (33 Replies)
Discussion started by: bioinfo
33 Replies

3. Shell Programming and Scripting

Help in awk/bash

Hi, I have two files: atom.txt and g.txt atom.txt has multiple patterns but I am showing only two patterns each ending with ENDMDL: ATOM 1 N SER A 1 35.092 83.194 140.076 1.00 0.00 N ATOM 2 CA SER A 1 35.216 83.725 138.725 1.00 0.00 C TER ENDMDL ATOM 1 N SER A 1 35.683 81.326 139.778 1.00... (11 Replies)
Discussion started by: bioinfo
11 Replies

4. UNIX for Dummies Questions & Answers

Help in awk/bash

Hi, I am also a newbie in awk and trying to find solution of my problem. I have one reference file 1.txt with 2 columns and I want to search other 10 files (a.txt, b.txt......h.txt each with 5 columns) corresponding to the values of 2nd column from 1.txt. If the value from 2nd column from 1.txt... (0 Replies)
Discussion started by: bioinfo
0 Replies

5. UNIX for Advanced & Expert Users

how to add new options in bash script

what i want to be is that i would like to reinvent new options that have the same functionality as ... -u is the same functionality of conv=ucase and -l have the same functionality as conv=lcase... is there a way that i can put these in my script so that whenever i will typed in command... (12 Replies)
Discussion started by: aphryllyn1
12 Replies

6. Shell Programming and Scripting

add up time with xx:yy format in bash how?

Hi, How can I add up a series of string like: and get a total as hour and minutes in a format like this: (3 Replies)
Discussion started by: bashily
3 Replies

7. Shell Programming and Scripting

bash scripting and awk help

Hey guys, i am fairly new to scripting and I am trying to write a script that takes a comma delimited file as input. I am trying to figure out a way to determine if $1 and $3 exist on a line (basically a hostname and ip address) and if true do the following, resolve the hostname to ip. sample... (6 Replies)
Discussion started by: streetfighter2
6 Replies

8. Shell Programming and Scripting

awk bash help

Hi, I'm trying to read a file containing lines with spaces in them. The inputfile looks like this ------------------------------ Command1 arg1 arg2 Command2 arg5 arg6 arg7 ------------------------------- The shell code looks like this... lines=`awk '{ print }' inputfile` ... (2 Replies)
Discussion started by: a-gopal
2 Replies

9. Shell Programming and Scripting

BASH with AWK

Hello, I have a file.txt with 20000 lines and 2 columns each which consists of current_filename and new_filename . I want to create a script to find files in a directory with current_filename and move it to new folder with new_filename. Could you please help me how to do that?? ... (2 Replies)
Discussion started by: narasimhulu
2 Replies

10. Shell Programming and Scripting

Bash - Add User script

Hey folks! I'm trying to work on a script that will add a user to the system. I have the complete script, but it's not working for me, and I'm not sure what to do. line 53: syntax error near unexpected token `0' ******************************************************** #!/bin/bash # # ... (4 Replies)
Discussion started by: niels.intl
4 Replies
Login or Register to Ask a Question