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 Optimiz...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 5 Topic 2172 of 2236
Post > Topic >>

Re: AWK Optimization

by dnlchen@[EMAIL PROTECTED] Feb 28, 2008 at 06:18 PM

On Feb 28, 4:43=A0am, Ed Morton <mor...@[EMAIL PROTECTED]
> wrote:
> On 2/27/2008 6:44 PM, dnlc...@[EMAIL PROTECTED]
 wrote:
>
>
>
>
>
> > Input (MySQL status):
>
> > | Com_select =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 | 16653146213 =A0 |
> > | Com_delete =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 | 43654772 =A0 =A0 =A0
=A0|=

> > | Com_insert =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0| 637410971 =A0 =A0
=A0|=

> > | Com_update =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0| 673829655 =A0 =A0 =A0|
>
> > Output:
> > Read Query #
> > Write Query #
>
> > Below script works, but I think there must be a concise AWK one.
>
> > #!/bin/sh
>
> > declare -i m n i j
>
> > m=3D`awk '$2 =3D=3D "Com_select" {print $4}' /var/log/mysql/status1`
> > n=3D`awk '$2 =3D=3D "Com_select" {print $4}' /var/log/mysql/status2`
>
> > i=3D`awk '$2 =3D=3D "Com_delete" || $2 =3D=3D "Com_insert" || $2
=3D=3D
> > "Com_update" {sum +=3D $4} END {print sum}' /var/log/mysql/status1`
> > j=3D`awk '$2 =3D=3D "Com_delete" || $2 =3D=3D "Com_insert" || $2
=3D=3D
> > "Com_update" {sum +=3D $4} END {print sum}' /var/log/mysql/status2`
>
> > awk -v Read1=3D$m -v Read2=3D$n 'BEGIN { printf( "%.4f\n", (Read2 -
Read=
1)/
> > 300 ) }'
> > awk -v Write1=3D$i -v Write2=3D$j 'BEGIN { printf( "%.4f\n", (Write2 -
> > Write1)/300 ) }'
>
> Something like this (untested):
>
> awk '
> $2=3D=3D"Com_select" {read[NR=3D=3DFNR] =3D $4}
> $2~/^Com_(delete|insert|update)$/ {write[NR=3D=3DFNR] +=3D $4}
> END {printf "%.4f\n%.f4\n", (read[0] - read[1])/300, (write[0] -
write[1])=
/300}
> ' /var/log/mysql/status1 /var/log/mysql/status2
>
this will ouput:
1030.0533
1944

my script's output:
1030.0533
193.7133

I can't tell which is correct;)

> If your posted input is truly all you have in the files (i.e. $2 is
always=
 one
> of the Com_* you show), then all you really need is:
>
> awk '$2=3D=3D"Com_select" {read[NR=3D=3DFNR] =3D $4; next}
{write[NR=3D=3D=
FNR] +=3D $4}
> END {printf "%.4f\n%.f4\n", (read[0] - read[1])/300, (write[0] -
write[1])=
/300}
> ' /var/log/mysql/status1 /var/log/mysql/status2
>
> =A0 =A0 =A0 =A0 Ed.- Hide quoted text -
>
> - Show quoted text -




 5 Posts in Topic:
AWK Optimization
dnlchen@[EMAIL PROTECTED]  2008-02-27 16:44:33 
Re: AWK Optimization
Janis <janis_papanagno  2008-02-28 01:49:37 
Re: AWK Optimization
Ed Morton <morton@[EMA  2008-02-28 06:43:38 
Re: AWK Optimization
dnlchen@[EMAIL PROTECTED]  2008-02-28 18:18:33 
Re: AWK Optimization
dnlchen@[EMAIL PROTECTED]  2008-02-28 18:22:36 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Sat May 17 2:15:11 CDT 2008.