On 12 Mar, 15:51, Luuk <L...@[EMAIL PROTECTED]
> wrote:
> di98mase schreef:
>
>
>
>
>
> > On 12 Mar, 15:28, Janis <janis_papanag...@[EMAIL PROTECTED]
> wrote:
> >> On 12 Mrz., 15:15, Luuk <L...@[EMAIL PROTECTED]
> wrote:
>
> >>> di98mase schreef:
> >>>> Hi
> >>>> I have a file with numbers in it. My program reads the values and
> >>>> compare them and depending on the value I increment a counter. what
I=
> >>>> have seen is that the evaluation fails. This is an extract of my
> >>>> numbers:
> >>>> 7
> >>>> 7
> >>>> 7
> >>>> 34
> >>>> 92
> >>>> 111
> >>>> 294
> >>>> 121
> >>>> 142
> >>>> This is parts of my program that checks the value (ms) read from
the
> >>>> file and increments the counters
> >>>> =A0 =A0 =A0 if( ms =3D=3D 18) t18++;
> >>>> =A0 =A0 =A0 if( ms =3D=3D 19) t19++;
> >>>> =A0 =A0 =A0 if( ms >=3D 20 && ms < 30)
> >>>> =A0 =A0 =A0 {
> >>>> =A0 =A0 =A0 =A0 =A0print ms;
> >>>> =A0 =A0 =A0 =A0 =A0t20++;
> >>>> =A0 =A0 =A0 }
> >>>> =A0 =A0 =A0 if( ms >=3D 30 && ms < 40) t30++;
> >>>> =A0 =A0 =A0 if( ms >=3D 40 && ms < 50) t40++;
> >>>> =A0 =A0 =A0 if( ms >=3D 50 && ms < 60) t50++;
> >>>> =A0 =A0 =A0 if( ms >=3D 60 && ms < 70) t60++;
> >>>> As you can see I dont have any numbers between 20 and 30 but I
still
> >>>> get an increment for the t20 counter. When I print the value it is
> >>>> "294". Why do I have this behaviour?
> >>> its compared alphanumeric
> >> The interesting question is; Why?
>
> >> And the answer might most likely be that 'ms' had been converted
> >> to a string somewhere in an unquoted part of his program (i.e.
> >> the opposite of the conversion you propose below). So if there's
> >> some code like
>
> >> =A0 =A0{ =A0ms =3D $1 ""
> >> =A0 =A0 =A0 ...
> >> =A0 =A0 =A0 if( ms =3D=3D 18) t18++;
> >> =A0 =A0 =A0 if( ms =3D=3D 19) t19++;
> >> =A0 =A0 =A0 if( ms >=3D 20 && ms < 30)
> >> =A0 =A0 =A0 ...
> >> =A0 =A0}
>
> >> It might be a more appropriateto fix the original number-to-string
> >> conversion.
>
> >> Janis
>
> >>> this will work:
> >>> if( 0+ms >=3D 20 && 0+ms < 30)
> >>> --
> >>> Luuk- Zitierten Text ausblenden -
> >>> - Zitierten Text anzeigen -- D=F6lj citerad text -
> >> - Visa citerad text -- D=F6lj citerad text -
>
> >> - Visa citerad text -
>
> > Hi all,
>
> > this is the missing part that converts from a string to an int that
> > was not shown in the previous post:
>
> > # Try to find out the transaction times from the logs that looks like:
> > # /I/TR End, Time:82433(89) Stat:0/0016e0dch:(
> > /TR End, / {
>
> > =A0 =A0match($3,"Time:")
> > =A0 =A0usecStart =3D RSTART + RLENGTH
> > =A0 =A0match($3,"[(]")
> > =A0 =A0usecEnd =3D RSTART
> > =A0 =A0usecLen =3D usecEnd - usecStart
> > =A0 =A0us =3D substr($3 , usecStart, usecLen)
>
> > =A0 =A0# Make sure that all found the matching pattern
> > =A0 =A0if (usecStart !=3D -1 && usecEnd !=3D -1 && usecLen !=3D -1)
> > =A0 =A0{
> > =A0 =A0 =A0 # Convert to ms and truncate decimals
> > =A0 =A0 =A0 temp =3D us/1000;
> > =A0 =A0 =A0 ms =3D sprintf ("%d", temp)
>
> > =A0 =A0 =A0 if( ms =3D=3D 1) t1++;
> > =A0 =A0 =A0 if( ms =3D=3D 2) t2++;
> > =A0 =A0 =A0 if( ms =3D=3D 3) t3++;
> > =A0 =A0 =A0 if( ms =3D=3D 4) t4++;
> > =A0 =A0 =A0 if( ms =3D=3D 5) t5++;
> > etc
> > etc
>
> > I thougth that the sprintf would convert the string to a number, or?
>
> man awk says:
> A number is converted to a string by using the value of CONVFMT as =A0a
> format =A0string =A0for =A0sprintf(3), =A0with =A0the =A0numeric
=A0value =
=A0of =A0the
> variable as the argument.
>
> so, if you want it to be numeric type:
> ms =3D 0 + sprintf ("%d", temp)
>
> but i did not test this to see if your equation will work ;-)
>
> --
> Luuk- D=F6lj citerad text -
>
> - Visa citerad text -
Ok, thanks Luuk . I am not sure if I understand the bit from the
manual but I will look it up and read about it.
I tested the solution to add 0+ as you suggested before and it worked
so I guess that this will work as well.
Thx
/di98mase


|