csv file - adding total to a trailer record

Hi,

I have a script which creates and modifies a csv file.

I have managed to do everything I need to do apart from 1 thing. I need to append a trailer record to the file. I need this line to hold the total of an entire column of the csv file (skipping the 1st line which is a header).

Can someone help, i had assumed the for loop would do the job but I am unsure how to specify the 3rd column and how to skip the first line.

Thanks

basically:

Input -

header record
detail record, 100, todays date
detail record, 100, todays date
detail record, 50, todays date

Output

header record
detail record, 100, todays date
detail record, 100, todays date
detail record, 50, todays date
trailer record, 250

For the trailer record:

$ awk '{s+=$3}END{print "trailer record, "s}' infile
trailer record, 250
1 Like

thanks - i love it when it is that easy (just need a bit more experience with this kind of thing).