I have this input:
Fred apples 20
Susy oranges 5
Mark watermellons 12
Robert pears 4
Robert oranges 17
Terry oranges 9
Lisa peaches 7
Susy oranges 12
Mark grapes 39
Anne mangoes 7
Greg pineapples 3
Oliver rockmellons 2
Betty limes 14
and I want output like this:
Anne:
mangoes 7
Oliver:
rockmellons 2
Greg:
pineapples 3
Mark:
watermellons 12
grapes 39
Terry:
oranges 9
Susy:
oranges 17
Lisa:
peaches 7
Fred:
apples 20
Robert:
oranges 17
pears 4
Betty:
limes 14
I am trying to do it with awk command. My code looks like this:
{
lines[$1] = (lines[$1] ? lines[$1] "\n " $2 " " $3 : $1 ":\n " $2 " " $3)
}
END {
for (line in lines) print lines[line]
}
I to compare duplicates in second collumn and sum the numbers.
+
or+=
operator.