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-29, 8:00 am

On Jan 28, 12:30=A0pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
> On 1/28/2008 11:21 AM, z.entropic wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
=A01/23/2008 19:55 6 =A0 =A0 =A0 1[color=darkred]
>
=A024480.25 =A0 =A0 =A0 =A014400.01 =A0 =A0 =A0 =A01/23/2008 19:55 6 =A0 =A0=
=A0 1[color=darkred]
>
=A024480.36 =A0 =A0 =A0 =A00.11 =A0 =A01/23/2008 19:55 7 =A0 =A0 =A0 1 =A0 =
=A0 =A0 0[color=darkred]
>
>
>
101[color=darkred]
[color=darkred]
e[color=darkred]
>
>
=3D$6;p3=3D$3;p11=3D$11}' file[color=darkred]
>
to need to[color=darkred]
>
>
ng[color=darkred]
>
, I[color=darkred]
>
e[color=darkred]
rm[color=darkred]
ld[color=darkred]
>
=A0 =A03.293399[color=darkred]
=A0 =A03.293234[color=darkred]
166826[color=darkred]
034836[color=darkred]
>
1][color=darkred]
[color=darkred]
>
>
} END{for (i in array)[color=darkred]
>
[color=darkred]
he[color=darkred]
>
ng a little[color=darkred]
>
>
>
ide[color=darkred]
>
eld[color=darkred]
you'd[color=darkred]
>
in array) print i[color=darkred]
>
>
g[color=darkred]
>
>
>
>
>
>
11=3D$11} END[color=darkred]
>
>
>
[color=darkred]
[color=darkred]
>
>
1}[color=darkred]
>
>
10;p11=3D$11}[color=darkred]
>
>
>
>
10;p11=3D$11}[color=darkred]
>
>
7=3D$7;p10=3D$10;p11=3D$11}[color=darkre
d]
>
>
>
>
>
>
>
>
>
>
>
[color=darkred]
; V11 =3D[color=darkred]
>
>
>
> I think you probably meant "||" rather than "&&".
>
>
> No, they aren't. It's a random order due to the way array indexing works i=

n awk.
> If you care about the order, use this:
>
> for (i=3D1;i<=3Dn;i++)
>
> instead of
>
> for (i in V)
>
>
> for (i=3D7;i<=3Dn;i++)
>
> Let's fix up the white space a bit for readability:
>
> ( 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; V11 =3D $11 }
> END { for (i=3D7;i<=3Dn;i++) print i, f[i], c[i], V[i], U[i] }
>
> and note that you don't NEED several different arrays to just print that
> information:
>
> ( NR < 8 ) || ( $7 < 6 ) { next }
> s7 && ( $7 !=3D s7 ) { V[++n] =3D FILENAME OFS c10 OFS V11 OFS $11 }
> { s7 =3D $7; c10 =3D $10; V11 =3D $11 }
> END { for (i=3D7;i<=3Dn;i++) print i, V[i] }
>
> Regards,
>
> =A0 =A0 =A0 =A0 Ed.- Hide quoted text -
>
> - Show quoted text -


Great thanks, Ed--that was a wonderful lesson--and a good starting
point for further exploits! Works just great!

z.e.
Sponsored Links







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

Copyright 2008 codecomments.com