Talk About Network

Google


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 15 Topic 2141 of 2317
Post > Topic >>

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

by Ed Morton <morton@[EMAIL PROTECTED] > Jan 24, 2008 at 12:58 PM

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.
 




 15 Posts in Topic:
compare values in the same field in consecutive rows--and store
"z.entropic" &l  2008-01-24 10:53:49 
Re: compare values in the same field in consecutive rows--and st
Ed Morton <morton@[EMA  2008-01-24 12:58:25 
Re: compare values in the same field in consecutive rows--and st
"z.entropic" &l  2008-01-24 11:19:28 
Re: compare values in the same field in consecutive rows--and st
Ed Morton <morton@[EMA  2008-01-24 13:41:45 
Re: compare values in the same field in consecutive rows--and st
Ed Morton <morton@[EMA  2008-01-24 13:52:12 
Re: compare values in the same field in consecutive rows--and st
"z.entropic" &l  2008-01-24 12:25:04 
Re: compare values in the same field in consecutive rows--and st
Ed Morton <morton@[EMA  2008-01-24 14:33:01 
Re: compare values in the same field in consecutive rows--and st
"z.entropic" &l  2008-01-24 14:35:52 
Re: compare values in the same field in consecutive rows--and st
Ed Morton <morton@[EMA  2008-01-24 16:40:22 
Re: compare values in the same field in consecutive rows--and st
"z.entropic" &l  2008-01-24 18:56:50 
Re: compare values in the same field in consecutive rows--and st
Ed Morton <morton@[EMA  2008-01-28 08:56:07 
Re: compare values in the same field in consecutive rows--and st
"z.entropic" &l  2008-01-28 07:46:59 
Re: compare values in the same field in consecutive rows--and st
"z.entropic" &l  2008-01-28 09:21:25 
Re: compare values in the same field in consecutive rows--and st
Ed Morton <morton@[EMA  2008-01-28 11:30:39 
Re: compare values in the same field in consecutive rows--and st
"z.entropic" &l  2008-01-29 05:34:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Fri Jul 25 20:17:07 CDT 2008.