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
Janis Papanagnou

2008-01-24, 7:02 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].


Assuming you mean field $10 of line n+1 (otherwise store $10 in f10 as
done with f4)...

awk 'f4==7 && $4==8 {a[NR-1]=$10} {f4=$4}'

(untested)

Janis

>
> Any help greatly appreciated.
>
> z.entropic

Sponsored Links







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

Copyright 2008 codecomments.com