Good Morning/Afternoon All,
I am having some trouble creating a variable called "total" to display the sum of the values in a specific field, $6 for example.
The data I am working on is in the following form:
John Doe:(555) 555-5555:1:2:3
Jane Doe:(544) 444-5556:4:5:6
Moe Doe:(654) 333-9999:7:8:9
I am using ":" as the field separator in order to have a total of 5 fields.
I then add the values in fields 3,4,5 to generate field 6
John Doe:(555) 555-5555:1:2:3:6
Jane Doe:(544) 444-5556:4:5:6:15
Moe Doe:(654) 333-9999:7:8:9:24
Now I want to add all the values in field 6 to generate a single total for the entire file, this is where I am stuck.
I currently have the following for my nawk script
nawk -F: '{split($0,six,":"); total=(six[3]+six[4]+six[5]); print total, NF}' filename
To my understanding, the above code creates an array "six" which stores all the values for each record(line) while using ":" as the separator.
I am thinking of storing the values in field 6 to a separate array called "dtotal" then doing a sum for all values in dtotal to give me the overall total for the file because I also need to display an average and highest value for field 6.
Any and all help is greatly appreciated.
Thanks in Advance.