Re: File parsing





On 11/29/2007 10:26 PM, vibgyorbits wrote:
k,very close...but this should fix almost everything!.

{ if (a[$2]=="") {
a[$2] = $1
}
else {
a[$2] = a[$2] - $1
print $2, a[$2]
a[$2]=""}

If you change the above to:

delete a[$2]

}

END {
for (i in a) {
if(a[i]!=""){ print i,a[i] }

then you can change the above to just:

print i,a[i]

since there'd be no unpopulated entries in "a".

}
}


You can simplify a little more too:

$2 in a { print $2, a[$2] - $1; delete a[$2]; next }
{ a[$2] = $1 }
END { for (i in a) print i, a[i] }

Regards,

Ed.


.