Re: File parsing



On Nov 29, 3:58 pm, Ed Morton <mor...@xxxxxxxxxxxxxx> wrote:
On 11/29/2007 3:35 PM, vibgyorbits wrote:



10 abc
20 abcc
30 abcd
40 xycz
42 wxy
5 abc
20 abcd
30 abcc

So, What i intend to do is:
Build an array or associatiave array...
such as

During the first pass:
search for the "FIRST" occurances of column 2.
So it would be:
"abc" - 10
"abcc" - 20
"abcd" - 30
& so on...

During the second pass:
search for the "SECOND" occurance of column2 & modify the earlier
array as:
"abc" 10 - 5 = "abc" 5
abcc 20 - 30 = "abcc" -10

I know this is doable in just one pass,but i'm stuck at:

1. I read the ffirst occurance of "abc" (column 2) - abc 10
2. I can NOT read until the next occurance ot "abc"- abc 5
3. I can NOT come back a LINE after where i was at step 1.

Is there a better / quicker way to do this?

PS # this is not a homework question, nor this is a puzzle / interview
qn. :)

Just check for the array[$2] already holding a value and, if not, populate it
with the current $1, otheriws subtract the current $1 from the current array[$2]
value:

awk '{a[$2]=(a[$2]=="" ? $1 : a[$2] - $1)} END{for (i in a) print i,a[i] }' file

Regards,

Ed.

super!,thanks a bunch..I had to modify my program little bit to
accomodate these changes.

.



Relevant Pages

  • Re: File parsing
    ... Build an array or associatiave array... ... I can NOT read until the next occurance ot "abc"- abc 5 ...
    (comp.lang.awk)
  • Re: File parsing
    ... I can NOT read until the next occurance ot "abc"- abc 5 ...
    (comp.lang.awk)
  • File parsing
    ... Build an array or associatiave array... ...
    (comp.lang.awk)
  • RE: cell ref
    ... entered as an array ... if there is more than one occurance, ... "ceemo" wrote: ... Prev by Date: ...
    (microsoft.public.excel.worksheet.functions)
  • Re: regular expression question
    ... however you will need to manually build the array. ... You can use the following RegEx to parse the string: ... > find occurances of two double quotes and an occurance of < and an ...
    (microsoft.public.dotnet.languages.vb)