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