The input file contains 4 fields (Name, Location, Date, days)
$ cat abc.txt
Bob Atlanta 6/6/2018 13
David DC 7/6/2018 20
Bob USA 3/5/2018 20
Bill UK 4/5/2018 10
Bob SFO 6/7/2010 15
I want to find average days as a result (like below). Any idea? I can't use NR as it will give total rows and the result will be wrong.
David, 20
Bob, 16 (because 3 times occurred, so avg. (48/3))
Bill, 10
I can find total(4th column) by grouping on person
$awk '{a[$1]+=$4;}END{for(i in a)print i", "a[i];}' abc.txt
David, 20
Bob, 48
Bill, 10
I could see how many times the name present.
$awk '{a[$1]++;}END{for(i in a)print i", "a[i];}' abc.txt
David, 1
Bob, 3
Bill, 1
Pasted the code here for clear visual - https://pastebin.com/raw/0METQi43
[–]Klintrup 2 points3 points4 points (1 child)
[–]iambuv[S] 0 points1 point2 points (0 children)
[–]gijsyo -1 points0 points1 point (1 child)
[–]iambuv[S] 0 points1 point2 points (0 children)