Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: compare val...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 2140 of 2241
Post > Topic >>

Re: compare values in the same field in consecutive rows--and store

by Janis Papanagnou <Janis_Papanagnou@[EMAIL PROTECTED] > Jan 24, 2008 at 08:00 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




 2 Posts in Topic:
compare values in the same field in consecutive rows--and store
"z.entropic" &l  2008-01-24 10:53:35 
Re: compare values in the same field in consecutive rows--and st
Janis Papanagnou <Jani  2008-01-24 20:00:55 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 7:53:25 CDT 2008.