Description
| $ ./distinct_lines.pl 3 hi hello world hi hello world hello world bye
3 distinct lines seen after 6 lines read. |
| $ ./distinct_lines.pl 3 hi hello world hi
hello world HELLO world bye 3 distinct lines seen after 6 lines read. |
| $ ./distinct_lines.pl 4 how are you are how are well
4 distinct lines seen after 7 lines read. |
| $ ./distinct_lines.pl 3 how are you
3 distinct lines seen after 3 lines read. |
| $ ./distinct_lines.pl 7 hello how are you
Ctrl-D End of input reached after 4 lines read – 7 different lines not seen. |
No error checking is necessary.
When you think your program is working you can autotest to run some simple automated tests:
$ 2041 autotest distinct_lines
When you are finished working on this exercise you must submit your work by running give:
$ give cs2041 test09_distinct_lines distinct_lines.pl
Your task is to write a Shell script eating.sh which prints a list of the food we have bought at the supermarket in the last week.
It will be given as its first argument a file containing a list of supermarket bills.
The file will be in this format:
[
[
{“name”: “Rice”, “price”: “$4.29”},
{“name”: “Butter”, “price”: “$4.00”}
],
[
{“name”: “Cheese”, “price”: “$8.82”},
{“name”: “Rice”, “price”: “$6.84”},
{“name”: “Pasta”, “price”: “$7.87”}
],
[
{“name”: “Peanut Butter”, “price”: “$6.93”},
{“name”: “Bread”, “price”: “$3.32”}, {“name”: “Noodles”, “price”: “$4.71”}
],
[
{“name”: “Cheese”, “price”: “$4.60”}, {“name”: “Rice”, “price”: “$8.23”},
{“name”: “Bread”, “price”: “$5.99”},
{“name”: “Pasta”, “price”: “$0.54”},
{“name”: “Ramen”, “price”: “$0.98”}
],
[
{“name”: “Noodles”, “price”: “$0.38”}
]
]
If eating.sh was given this file as its first argument it should print
Bread
Butter
Cheese Noodles
Pasta
Peanut Butter
Ramen
Rice
bills.json contains an example list of bills
Download bills.json, or copy it to your CSE account using the following command:
$ cp -n /web/cs2041/20T2/activities/eating/bills.json .
Here is how eating.sh should behave:
| $ eating.sh bills.json
Bread Butter Cheese Noodles Pasta Peanut Butter Ramen Rice |
You must print the food in alphabetic order.
Each type of food must be printed only once.
Your function does not have to handle differences in case or white-space.
You can assume the formating of the file is the same as the example above. Your program does not have to handle the many other ways a JSON file might be formatted.
You can assume the “name” and “price” fields are always in the same order as the above example. Your answer must be Shell. You can not use other languages such as Perl, Javascript, Python or C.
No error checking is necessary.




