January 12, 2021

Today’s task is from a beginning programmer, who starts with an input file called animal.txt:

There once was a Dog

Wednesday he ate Apples 
Thursday he ate Apples
Friday he ate Apples
Saturday he ate carrots

There once was a Bear

Tuesday he ate carrots
Wednesday he ate carrots
Thursday he ate chicken

He wants to create this output:

Food: Apples Animals who ate it: 1

Food: Carrots Animals who ate it: 2

Food: Chicken Animals who ate it: 1

He gave a complicated awk solution that didn’t work; it produced duplicate lines of output in those cases
where the same animal ate the same food on multiple days.

Your task is to write a program to produces the desired transformation form input to output. When
you are finished, you are welcome to read or run a suggested solution, or to post your own solution or
discuss the exercise in the comments below.


Pages: 1 2