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: I'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 == 7 in the n-th row, and field $4 == 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=4 '$f==(p+1){array[NR]=$10} {p=$f}' file
or this:
awk -v f=4 '($f==8)&&(p==7){array[NR]=$10} {p=$f}' file
should do it.
Ed.


|