Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: awk 'system...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 11 of 12 Topic 2171 of 2236
Post > Topic >>

Re: awk 'system("date +%s -d ")'

by dnlchen@[EMAIL PROTECTED] Feb 29, 2008 at 06:04 PM

On Feb 27, 12:56=A0am, Janis <janis_papanag...@[EMAIL PROTECTED]
> wrote:
> On 27 Feb., 08:29, "DanielC" <dnlc...@[EMAIL PROTECTED]
> wrote:
>
> > "Ed Morton" <mor...@[EMAIL PROTECTED]
> wrote in message
> >news:47C25043.1000302@[EMAIL PROTECTED]
>
> > > On 2/24/2008 5:34 PM, DanielC wrote:
>
> > > [ for the second time - please don't top-post, fixed below]
>
> > What does this mean?
>
> http://www.caliburn.nl/topposting.html
>
> [...]
>
>
>
> > A question: how do we use awk to process a very large file (ie. 500000
> > lines) by reading file from bottom to top?
> > I know we can use array to reverse a small file, and we can also apply
i=
t on
> > the big file. However that costs too much, and it is not suitable for
a
> > frequent job.
>
> Yes, to efficiently process large files you would take a tool that is
> more appropriate for the task. On Unix you may find 'tac' for that.
>
> Janis

# time tac p20080229.log | awk '
BEGIN
{ now=3Dsystime(); tgt=3D120* 60 }
{ then=3Dmktime(gensub(/\[(....)-(..)-(..) (..):(..):(..).*/,"\\1 \\2 \
\3 \\4 \\5 \\6","")) }
{ if ((now - then) < tgt) {count[$5]++} else exit }
END
{ for (pid in count) print pid,count[pid] }' | sort -k1

449 18
547 20
548 13
549 5
550 9
551 10
552 8
553 21
554 6
555 24
556 21
557 11
558 11
559 15
560 19
561 27
562 25
563 11
579 6
581 1
582 17

real    0m0.019s
user    0m0.014s
sys     0m0.005s

# ls -l p20080229.log
-rw-rw-rw-  1 root root 33854251 Mar  1 00:00 p20080229.log
# wc -l p20080229.log
573838 p20080229.log
# date
Sat Mar  1 02:00:30 GMT 2008

It works great! Thanks Ed and Janis.

DanielC




 12 Posts in Topic:
awk 'system("date +%s -d ")'
"DanielC" <d  2008-02-24 13:06:04 
Re: awk 'system("date +%s -d ")'
Ed Morton <morton@[EMA  2008-02-24 15:23:36 
Re: awk 'system("date +%s -d ")'
"DanielC" <d  2008-02-24 13:50:28 
Re: awk 'system("date +%s -d ")'
Ed Morton <morton@[EMA  2008-02-24 15:56:40 
Re: awk 'system("date +%s -d ")'
"DanielC" <d  2008-02-24 14:36:52 
Re: awk 'system("date +%s -d ")'
Ed Morton <morton@[EMA  2008-02-24 17:04:05 
Re: awk 'system("date +%s -d ")'
"DanielC" <d  2008-02-24 15:34:58 
Re: awk 'system("date +%s -d ")'
Ed Morton <morton@[EMA  2008-02-24 23:21:07 
Re: awk 'system("date +%s -d ")'
"DanielC" <d  2008-02-26 23:29:11 
Re: awk 'system("date +%s -d ")'
Janis <janis_papanagno  2008-02-27 00:56:02 
Re: awk 'system("date +%s -d ")'
dnlchen@[EMAIL PROTECTED]  2008-02-29 18:04:36 
Re: awk 'system("date +%s -d ")'
mik3l3374@[EMAIL PROTECTE  2008-02-25 01:07:27 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 11:42:22 CDT 2008.