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 ) }'