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 2 of 5 Topic 2172 of 2241
Post > Topic >>

Re: AWK Optimization

by Janis <janis_papanagnou@[EMAIL PROTECTED] > Feb 28, 2008 at 01:49 AM

On 28 Feb., 01:44, 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.

Yes. Do everything in one awk script. The key is to read both
files and distinguish your operations depending on which file
you are perocessing. The frame is...

awk '
NR=3D=3DFNR {
  # do the things to be done for file "status1"
  next;
}
NR!=3DFNR {
  # do the things to be done for file "status2"
  next;
}
' var/log/mysql/status1 var/log/mysql/status2

You will extend the above conditions "NR <op> FNR" by the
conditions you have in your various awk calls, and you will
use separate variables to sum up things. The read/write
calculations will be done in the END section.

Janis

>
> #!/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 -
Read1)=
/
> 300 ) }'
> awk -v Write1=3D$i -v Write2=3D$j 'BEGIN { printf( "%.4f\n", (Write2 -
> Write1)/300 ) }'




 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 5:48:29 CDT 2008.