Re: File parsing
- From: vibgyorbits <bkajey@xxxxxxxxx>
- Date: Thu, 29 Nov 2007 19:05:11 -0800 (PST)
K, could u please explain little bit detailed on this?
is the indexing in awk automatic???
thanks
On Nov 29, 4:55 pm, vibgyorbits <bka...@xxxxxxxxx> wrote:
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.
.
- Follow-Ups:
- Re: File parsing
- From: vibgyorbits
- Re: File parsing
- References:
- File parsing
- From: vibgyorbits
- Re: File parsing
- From: Ed Morton
- Re: File parsing
- From: vibgyorbits
- File parsing
- Prev by Date: Re: File parsing
- Next by Date: Re: File parsing
- Previous by thread: Re: File parsing
- Next by thread: Re: File parsing
- Index(es):
Relevant Pages
|