home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!coplex!trebor!root
- From: root@trebor.uucp (Bob Stockler)
- Subject: Re: Performing simple math on a numeric file from csh
- Organization: Bob Stockler
- Date: Fri, 18 Dec 1992 04:31:03 GMT
- Message-ID: <1992Dec18.043103.12267@trebor.uucp>
- References: <1992Dec16.080343.24756@netcom.com>
- Lines: 38
-
- dman@netcom.com (Dallman Ross) writes:
-
- >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
- >>
- >(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.
-
- The problem is that you're trying to do "date" math with the math facilities
- "awk" has (which are just plain math stuff).
-
- I have a program that does what you want to do, but instead I'll assign
- you the task using these guidelines:
-
- 1) "awk" sees the last field in a line as $NF
-
- 2) the "split" function can separate a field using ":"
-
- 3) you need to convert each value to seconds, total them, and
- then do math on that
-
- 4) then convert the value back using modular arithmetic
-
- This isn't the ultimate answer, since "login-logout" lines might span
- midnight, so you have to consider that.
-
- Let me know what you come up with.
- --
- Bob Stockler bob@trebor.uucp CIS: 72726,452
-