For Programmers: Free Programming Magazines  


Home > Archive > AWK > January 2008 > Re: compare values in the same field in consecutive rows--and store









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: compare values in the same field in consecutive rows--and store
z.entropic

2008-01-28, 7:02 pm

On Jan 28, 9:56=A0am, Ed Morton <mor...@lsupcaemnt.com> wrote:
> On 1/24/2008 8:56 PM, z.entropic wrote:
>
>
>
>
>
>
>
>
>
>
1/23/2008 19:55 6 =A0 =A0 =A0 1[color=darkred]
>
> =A0 0 =A0 =A0 =A0 0 =A0 =A0 =A0 3.293 =A0 1.287>>>>>>>101 =A0 =A0 =A0 =A02=

4480.25 =A0 =A0 =A0 =A014400.01 =A0 =A0 =A0 =A01/23/2008 19:55 6 =A0 =A0 =A0=
1
>
> =A0 0 =A0 =A0 =A0 0 =A0 =A0 =A0 3.296 =A0 1.288>>>>>>>102 =A0 =A0 =A0 =A02=

4480.36 =A0 =A0 =A0 =A00.11 =A0 =A01/23/2008 19:55 7 =A0 =A0 =A0 1 =A0 =A0 =
=A0 0
>
> =A0 -0.00185954 =A0 =A0 3.167 =A0 1.287
>
>
>
>
>
>
1[color=darkred]
>
>
=3D$6;p3=3D$3;p11=3D$11}' file[color=darkred]
>
o need to[color=darkred]
>
>
[color=darkred]
>
I[color=darkred]
>
[color=darkred]
[color=darkred]
>
=A03.293399[color=darkred]
=A03.293234[color=darkred]
6826[color=darkred]
4836[color=darkred]
>
[color=darkred]
>
>
END{for (i in array)[color=darkred]
>
[color=darkred]
>
a little[color=darkred]
>
>
>
e[color=darkred]
>
d[color=darkred]
ou'd[color=darkred]
>
n array) print i[color=darkred]
>
>
>
>
>
>
>
>
1=3D$11} END[color=darkred]
>
> ITYM c[++m]=3Dp10 instead of c[++m]=3D=3Dp10.
>
>
>
> If you don't want n to increase twice, just don't increment it twice:
>
> awk 'p7&&($7!=3Dp7){V[++n]=3Dp11;c[n]=3Dp10} {p7=3D$7;p10=3D$10;p11=3D$11}=


> END{for (i in V) print i, V[i],c[i]}'
>
>
>
>
> awk 'p7&& ($7!=3Dp7){V[++n]=3Dp11;c[n]=3Dp10;d[n]=
3D$11} {p7=3D$7;p10=3D$10=

;p11=3D$11}
> END{for (i in V) print i, V[i],c[i],d[i]}'
>
>
> awk 'p7&& ($7!=3Dp7){V[++n]=3Dp11;c[n]=3Dp10;d[n]=
3D$11,e[n]=3DFILENAME}
> {p7=3D$7;p10=3D$10;p11=3D$11}
> END{for (i in V) print i, V[i],c[i],d[i],e[i]}'
>
> but you don't need to store it if it's just one input file:
>
> awk 'p7&& ($7!=3Dp7){V[++n]=3Dp11;c[n]=3Dp10;d[n]=
3D$11} {p7=3D$7;p10=3D$10=

;p11=3D$11}
> END{for (i in V) print i, V[i],c[i],d[i],FILENAME}'
>
>
> awk 'NR<=3D10{next}
> p7&& ($7!=3Dp7){V[++n]=3Dp11;c[n]=3D=3Dp10;d[
n]=3D$11,e[n]=3DFILENAME} {p7=

=3D$7;p10=3D$10;p11=3D$11}
> END{for (i in V) print i, V[i],c[i],d[i],e[i]}'
>
>
>
>
> I don't know what you mean by that.
>
>
> Just follow the pattern....
>
> =A0 =A0 =A0 =A0 Ed.- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -


I took your latest script, cleaned it up a bit for clarity, changed
some letters (to make them more meaningful for me during the debugging
and learning process--and it almost works the way I would want it to
work!

( NR < 8 ) && ( $7 < 6 ) { next } s7 && ( $7 !=3D s7 ) { V[++n] =3D V11;
c[n] =3D c10; U[n] =3D $11; f[n] =3D FILENAME } { s7 =3D $7; c10 =3D $10; V1=
1 =3D
$11 } END { for (i in V ) print i, f[i], c[i], V[i], U[i] }

However, I still have a few problems:

1. the first two inequalities seem to be disregarded, and unwanted
data are stored in the array and then printed out.
2. the data are printed out in reverse order (from the highest i to
1... how come?
3. how to impose an i>6 condition in the last 'for' printout loop (see
#1).

z.e.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com