home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / question / 14871 < prev    next >
Encoding:
Text File  |  1992-12-22  |  2.4 KB  |  68 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!nwnexus!Celestial.COM!ray
  3. From: ray@Celestial.COM (Ray Jones)
  4. Subject: Re: Performing simple math on a numeric file from csh
  5. Organization: Celestial Software, Mercer Island, WA
  6. Date: Tue, 22 Dec 1992 00:20:39 GMT
  7. Message-ID: <1992Dec22.002039.28769@Celestial.COM>
  8. References: <1992Dec16.080343.24756@netcom.com> <1992Dec17.093546.9935@netcom.com>
  9. Lines: 57
  10.  
  11. In <1992Dec17.093546.9935@netcom.com> dman@netcom.com (Dallman Ross) writes:
  12.  
  13. >I, Dallman Ross (dman@netcom.com), wrote:
  14. >: I am trying to understand awk, but the man pages are driving me nuts. 
  15. >: Anyway, I have a couple of simple files with numerics in them that I
  16. >: want to do some math with.  This doesn't have to be via awk, but I've
  17. >: been told that's the ticket.  Anyway, I use csh.
  18. >:  
  19. >: Here's what one of the files looks like:
  20. >:  
  21. >: > login:  Dec 15 21:40:01
  22. >: > logout: Dec 15 21:40:18
  23. >: > 
  24. >: > login:  Dec 15 21:41:11
  25. >: > logout: Dec 15 21:41:48
  26. >: > 
  27. >: > login:  Dec 15 22:20:08
  28. >: > logout: Dec 15 22:31:44
  29. >: > 
  30. >:  
  31. >: (No >'s in the file, of course.)  So, I want to subtract the
  32. >: penultimate time figure from the last figure, and come up with
  33. >: "00:11:36" as the answer for time logged in.  I only need to do the
  34. >: math on the last pair.  The rest is just a running log.
  35. >:  
  36. >: Thanks for any advice.
  37.  
  38. >Still hoping for some help on this.  One person did email me, but I
  39. >haven't seen any tips on command lines yet.
  40.  
  41. I think awk may be the easier way to go, but I don't know much about it
  42. either.  I would use a bourne shell script with something like the
  43. following:
  44.  
  45. tail -2 logfile>tmp.$$    # get the last entries
  46. set `grep login tmp.$$|sed -e "s/:/ /"`    # where 
  47. hin=$4     #hour of login
  48. min=$5     #minute of login
  49. sin=$6     #second of login
  50. set `grep logout tmp.$$|sed -e "s/:/ /"`    # where
  51. hout=$4     #hour of logout
  52. mout=$5     #minute of logout
  53. sout=$6     #second of logout
  54. # now you can use "bc" to do all the numbers
  55. t_hr=`echo "$hout-$hin" |bc`
  56. t_min=`echo "$mout-$min" |bc`
  57. t_sec=`echo "$sout-$sin" |bc`
  58. echo "login hours = $t_hr"
  59. echo "login minutes = $t_min"
  60. echo "login seconds = $t_sec"
  61. rm tmp.$$
  62. # crude, but it should work.
  63. -- 
  64. INTERNET:  ray@Celestial.COM   Ray A. Jones; Celestial Software
  65. UUCP:   ...!thebes!camco!ray   6641 East Mercer Way
  66.              uunet!camco!ray   Mercer Island, WA 98040; (206) 947-5591
  67. The probability of one or more spelling errors in this missive approaches
  68.