The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
extract set of matching records finder255 Shell Programming and Scripting 4 12-24-2008 06:04 AM
How can you delete records in a file matching a pattern? mode09 UNIX for Dummies Questions & Answers 2 07-15-2008 02:53 PM
deleting multiple records from a huge file at one time dsravan Shell Programming and Scripting 5 02-06-2008 11:17 AM
Sh scripting problem, matching specific white space Dickalicious Shell Programming and Scripting 7 05-24-2006 02:30 PM
C shell script for time matching Ringo Shell Programming and Scripting 1 08-07-2003 02:26 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 05-06-2009
Gonik Gonik is offline
Registered User
  
 

Join Date: May 2009
Posts: 2
awk scripting - matching records and summing up time

Hello. I just found out about awk, and it appears that this could handle the problem I'm having right now.

I first stumbled on the thread How to extract first and last line of different record from a file, and that problem is almost similar to mine.

In my case, an ASCII file will contain the following fields, among many others:
record date time code
----------------------------
dd 1-3-2006 1:00:20 AM 2
aa 1-2-2006 8:34:21 AM 1
bb 1-2-2006 7:34:21 AM 1
aa 1-2-2006 10:30:22 AM 2
cc 1-2-2006 10:34:21 AM 1
aa 1-2-2006 15:30:22 AM 3
dd 1-2-2006 8:04:11 PM 1
aa 1-2-2006 6:24:44 PM 1
bb 1-2-2006 10:30:22 AM 2
aa 1-2-2006 11:03:19 AM 2
aa 1-2-2006 16:03:19 AM 3
bb 1-2-2006 12:03:19 PM 2
cc 1-2-2006 4:04:11 PM 1
dd 1-3-2006 12:20:00 AM 2
bb 1-2-2006 7:24:44 PM 1
dd 1-3-2006 2:20:02 AM 1
....
.
.


At the end of any given interval of days, I am trying to output
aa <total time>
bb <total time>
cc <total time>
dd <total time>

Where total total time elapsed from matching code 1 are deducted by total time elapsed from matching codes 2 and 3, and so forth.

(example from above sample, sorted to display matching records)
aa 1-2-2006 8:34:21 AM 1
aa 1-2-2006 6:24:44 PM 1 (total time 1: X)
aa 1-2-2006 10:30:22 AM 2
aa 1-2-2006 11:03:19 AM 2 (total time 2: Y)
aa 1-2-2006 15:30:22 AM 3
aa 1-2-2006 16:03:19 AM 3 (total time 3: Z)

total time = X-(Y+Z)

I'm hoping to do it with Python but I've seen some awesome awk scripts and I'm wondering if it could be done with awk instead.

I'm also confounded with computing time past midnight. (ie record dd). If code records don't match, total time is not computed but is marked in the output as
xx "data error"
 

Bookmarks

Tags
elapsed time

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0