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



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.

.



Relevant Pages

  • Re: vb.net class
    ... about fixed array lenghts or using ReDim statements. ... code ensures everything in the array is a String because you declare it ... Count can be generated from the time list, not need to store ...
    (microsoft.public.dotnet.languages.vb)
  • Re: new to Perl - please verify my script?
    ... You can store the shipping total ... the number in the array corresponds to the number of items. ... have different shipping rate for different parts of the world. ...
    (comp.lang.perl.misc)
  • Re: Was this a bug
    ... that you didn't store in memory somewhere ... outside the array that you were trying to store in? ...
    (comp.lang.fortran)
  • Re: THATS IT !!
    ... and threw away the store. ... That's an intelligent compiler. ... lot of work to find out that an array element is ...
    (sci.crypt)
  • Re: How to list the statement of all var ?
    ... > of an object when the question was about `var' statements? ... And as soon as i will test it for this particular host ... to use an Object object instead of an Array object. ...
    (comp.lang.javascript)