On Jan 24, 1:58=A0pm, Ed Morton <mor...@[EMAIL PROTECTED]
> wrote:
> On 1/24/2008 12:53 PM, z.entropic wrote:
>
> > I know it's a pretty basic question for true (g)awkers, but I've spent
> > enough time today to try to make it work... I need your help...
>
> > Here is the problem: =A0I'd like to scan large data files, find
> > consecutive lines in which a given field has a particular value,
> > extract a value in another field and store it in an array for
> > subsequent calculation.
>
> > An example: if field $4 =3D=3D 7 in the n-th row, and field $4 =3D=3D
8 =
in the
> > n+1st row, store the value of field $10 in array[n].
>
> Depending on what you really mean above, either this:
>
> awk -v f=3D4 '$f=3D=3D(p+1){array[NR]=3D$10} {p=3D$f}' file
>
> or this:
>
> awk -v f=3D4 '($f=3D=3D8)&&(p=3D=3D7){array[NR]=3D$10} {p=3D$f}' file
>
> should do it.
>
> =A0 =A0 =A0 =A0 Ed.
Thanks, Ed, for your super-fast reply. I've tried both scripts, but
did they did not work. Here is a fragment of my input file:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
100 24479.33 14399.09 1/23/2008 19:55 6 1 0 0 3.293 1.287
101 24480.25 14400.01 1/23/2008 19:55 6 1 0 0 3.296 1.288
102 24480.36 0.11 1/23/2008 19:55 7 1 0 -0.00185954 3.167 1.287
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Thus, if field $6 in line 100 is equal to 6 AND field $6 in line 101
is equal to 7, store the value 14399.09 in array1[1] and 1.287 in
array2[1]. When the next match is found, store the two values in
array1[2] and array2[2], etc. Basically, I'm comparing the same
fields in consecutive rows.
z.entropic


|