[TriLUG] Awk question
Mark Freeze
mfreeze at gmail.com
Tue Aug 7 14:52:51 EDT 2007
Hello everyone,
I have a piece of code that I was going to program in Perl, but
someone told me that awk could handle it faster and more efficiently
and I was wondering if anyone could help me with the particulars as I
am not experienced at all with using awk.
The tab-delimited file has the following fields:
LCode, Packet, AccountNum, CustID, Balance.
Example: (Using - for a delimiter instead of tabs)
RXX - 0115 - 12345 - 15077 - 20.50
RZA - 0115 - 12345 - 15077 - 35.00
RET - 0117 - 54321 - 19004 - 70.23
RET - 0117 - 54322 - 19100 - 20.00
RET - 0117 - 54324 - 19700 - 115.99
RET - 0117 - 54323 - 19233 - 78.50
RAB - 0119 - 28033 - 21001 - 18.78
BFR - 0110 - 78745 - 13701 - 5.00
BFR - 0110 - 78749 - 19720 - 1.00
BFR - 0110 - 78746 - 14500 - 8.23
BFR - 0110 - 78748 - 45004 - 100.00
I need to summarize the balance for the groups of records that have
the same LCode and Packet, place the summarized total on the balance
field of the record containing the highest AccountNum, and output only
that record for the group. (And single records...) That operation
would make a file that looked like this:
RXX - 0115 - 12345 - 15077 - 20.50
RZA - 0115 - 12345 - 15077 - 35.00
RET - 0117 - 54324 - 19700 - 284.72
RAB - 0119 - 28033 - 21001 - 18.78
BFR - 0110 - 78749 - 19720 - 114.23
Any suggestions on how to do this with awk? Can it be done? Better
and faster than Perl?
Thanks,
Mark.
More information about the TriLUG
mailing list