I am trying to write a script that will read all of the lines of a csv file and add up the numbers in one of the fields. For example, the csv fields are similar to:
Date|account#|account type|work description|balance

There can be several hundred lines in each file. I would like to read all of the balances from each line and add them up. It's also important to know that there are multiple lines with the same account#. I only need to include one of the lines in the summation if the account# appears more than once.

So far I have this code:
 Code:
$csv="C:\temp\test.csv"
Open(3,$csv) = 0
$read=ReadLine(3)
$csv_array=Split($read,"|")
? $csv_array[5] ;this is the account# field
? $csv_array[66] ;this is the balance field


This just reads the first line of the file. So my questions are:

1. How do I loop through each line of the file to get each balance value and save that in an array to add together later.

2. How do I prevent the balance from being added to the array if that account number has already been read.

I hope this makes sense.

Thanks.