Re: Log file reduction
- From: michal@xxxxxxxxxxxxxxxxxxxxxxx
- Date: Fri, 12 Aug 2011 00:32:58 +0000 (UTC)
Ed Morton <mortonspam@xxxxxxxxx> wrote:
On 8/11/2011 1:54 AM, Hermann Peifer wrote:
On 11/08/2011 00:21, chessdr wrote:
On Aug 2, 9:20 am, "Ed Morton"<mortons...@xxxxxxxxx> wrote:
chessdr<ches...@xxxxxxxxx> wrote:
<snip>
The below GAWK script is working perfectly!! Thanks for your help.
Now I've been given the task to make this work with NAWK, so I
understand the systime() function isn't there, as well as the mktime()
function?
Correct, the time functions are some of the very useful gawk extensions.
Just
say "no" to nawk. Think of it as "No! AWK" ;-). Seriously, it's not even a
POSIX awk, it's just "new"er than old, broken awk. Why do you need to use it
instead of gawk?
Ed.
Posted usingwww.webuse.net
Unfortunately we only have NAWK and AWK installed on our production
UNIX boxes, but after seeing how much more useful GAWK is, I think
it's worth pursuing finding out why we can't get it installed instead.
Without gawk's systime() and mktime() functions, I could imagine that the below
code *could* work with nawk (assuming that you are interested in a time
difference in days, leaving out the details of hours, minutes, seconds, time
zones and daylight saving time issues). Ed might have an opinion on potential
getline caveats.
Hermann
BEGIN {
# Today's date, in YYYYMMDD format
"date +%Y%m%d" | getline today
All I'd say about getline there is you don't need it as you could just pass in
the date:
awk -v today="$(date +%Y%m%d)" '...'
I would use instead a "seconds" format.
awk -v today=$(date +%s)
'date' will readily convert various assorted date formats to that one,
so a timestamp conversion inside awk program becomes easy with
'date' and 'getline', and after that timestamp comparisons are just
trivial. All kind of headaches immediately go away.
Timestamps like "[Mon Oct 25 14;59;07 2011]" will be not accepted but
converting that to
date -d "Mon Oct 25 14:59:07 2011" +%s
is not really a rocket science (that prints in my timezone 1319576347).
Or maybe ';' instead of ':' is just locale dependent?
Not sure if nawk supports using getline reading from a pipe anyway.
Er..., it has to or it would not be any kind of AWK at all.
BTW - if you want comparisons with a midnight of today then use
as a starting point
date -d "$(date +%Y%m%d)" +%s
Michal
.
- Follow-Ups:
- Re: Log file reduction
- From: Ed Morton
- Re: Log file reduction
- References:
- Re: Log file reduction
- From: chessdr
- Re: Log file reduction
- From: Ed Morton
- Re: Log file reduction
- From: chessdr
- Re: Log file reduction
- From: Hermann Peifer
- Re: Log file reduction
- From: Ed Morton
- Re: Log file reduction
- Prev by Date: Re: Matching fields in two files.....
- Next by Date: Re: Log file reduction
- Previous by thread: Re: Log file reduction
- Next by thread: Re: Log file reduction
- Index(es):
Relevant Pages
|