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 4 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 01:41 PM

On 1/24/2008 1:19 PM, z.entropic wrote:
<snip>
>  Here is a fragment of my input file:
> 
> ============
> 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
> =============
> 
> 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.

Try this:

awk '($6==7)&&(p6==6){array1[++n]=p3;array2[n]=p11} {p=$6;p3=$3;p11=$11}'
file

You should use an array for the "p" (previous) field values if you to need
to
access more of them.

	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 Sat Jul 26 2:17:42 CDT 2008.