The pipeline from Linux Essentials answers "which one, and how often?" In a script, with "$1" for the file, it works on any day's file.
learner@reef:~$ cut -d, -f2 refunds.csv | sort | uniq -c | sort -rn | head -n 3
4 south ← the shop with the most refunds
2 north
1 webuniq -c only merges repeats that are next to each other, so sort comes first.
Every evening, Ana bakes more of what sold best. ~/sales.csv has a line for each item sold today, like 07:33,north,croissant,2.40: time, shop, item, price.
-
At the prompt, build the pipeline one
|at a time, starting withcuton the item, field 3. -
When it prints the five best sellers, put that line in
~/best-sellers.sh, under#!/bin/bash, with"$1"for the file. -
Run
chmod u+x ~/best-sellers.sh, then run it:textlearner@reef:~$ ./best-sellers.sh ~/sales.csv 9 croissant …
The tests also run it on another day's file, one with a space in its name.
Objectives
./best-sellers.sh ~/sales.csvprints the five best sellers, most first, with their counts.- It works for another day's file, one with a space in its name.