Re: Log file reduction



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

.



Relevant Pages

  • Re: Using getline in AWK in a Shell function to read from standard input
    ... while ("ls -1" | getline) print ... The above isn't an appropriate application for awk as awk is just ... being used to invoke shell commands which is precisely what shell is ... poster to make the code comparable. ...
    (comp.lang.awk)
  • Re: Using getline in AWK in a Shell function to read from standard input
    ... while ("ls -1" | getline) print ... The above isn't an appropriate application for awk as awk is just ... being used to invoke shell commands which is precisely what shell is ... poster to make the code comparable. ...
    (comp.lang.awk)
  • getline caveats misuse howto: final version
    ... The following, composed by Ed Morton to address the recurring issue of getline use, was based primarily on information from the book "Effective Awk Programming", Third Edition By Arnold Robbins; with review and additional input from many of the comp.lang.awk regulars, including Steve Calfee, ... program rather than learning the easier way that awk was designed to ... "The getline command is used in several different ways and should not be ... getline var < file var ...
    (comp.lang.awk)
  • Re: Script - Strip headers from message - please help optimize.
    ... I am not familiar with AWK. ... I think your main problem is with using getline inside the automatic ... The problem with it not executing directly is probably due ... if a line wraps, the wrap stands out. ...
    (comp.lang.awk)
  • Re: newbie help with first program
    ... I don't see this point, the gawk manual clearly outlines use of getline to open secondary datafiles, ... You mentioned in another post that you're new to awk. ... they don't know what constructs the C++ language provides to support that paradigm ... Since C++ is a multi-paradigm language, it allows you to write procedural programs and so they end up just doing that. ...
    (comp.lang.awk)