home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / unix / question / 14811 < prev    next >
Encoding:
Text File  |  1992-12-21  |  1.7 KB  |  49 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!coplex!trebor!root
  3. From: root@trebor.uucp (Bob Stockler)
  4. Subject: Re: Performing simple math on a numeric file from csh
  5. Organization: Bob Stockler
  6. Date: Fri, 18 Dec 1992 04:31:03 GMT
  7. Message-ID: <1992Dec18.043103.12267@trebor.uucp>
  8. References: <1992Dec16.080343.24756@netcom.com>
  9. Lines: 38
  10.  
  11. dman@netcom.com (Dallman Ross) writes:
  12.  
  13. >I am trying to understand awk, but the man pages are driving me nuts. 
  14. >Anyway, I have a couple of simple files with numerics in them that I
  15. >want to do some math with.  This doesn't have to be via awk, but I've
  16. >been told that's the ticket.  Anyway, I use csh.
  17. >Here's what one of the files looks like:
  18. >> login:  Dec 15 21:40:01
  19. >> logout: Dec 15 21:40:18
  20. >> 
  21. >(No >'s in the file, of course.)  So, I want to subtract the
  22. >penultimate time figure from the last figure, and come up with
  23. >"00:11:36" as the answer for time logged in.  I only need to do the
  24. >math on the last pair.  The rest is just a running log.
  25.  
  26. The problem is that you're trying to do "date" math with the math facilities
  27. "awk" has (which are just plain math stuff).
  28.  
  29. I have a program that does what you want to do, but instead I'll assign
  30. you the task using these guidelines:
  31.  
  32.     1) "awk" sees the last field in a line as $NF
  33.  
  34.     2) the "split" function can separate a field using ":"
  35.  
  36.         3) you need to convert each value to seconds, total them, and
  37.            then do math on that
  38.  
  39.         4) then convert the value back using modular arithmetic
  40.  
  41. This isn't the ultimate answer, since "login-logout" lines might span
  42. midnight, so you have to consider that.
  43.  
  44. Let me know what you come up with.
  45. -- 
  46. Bob Stockler                  bob@trebor.uucp                  CIS: 72726,452
  47.