Terminal Exercises
Help 22 / 25
Finding Things

Tracking a species

Go to the folder exercise-data/:

cd $TUTORIAL/exercise-data/

Leah has several hundred data files saved in one directory, each of which is formatted like this:

2012 - 11 - 05, deer, 5;
2012 - 11 - 05, rabbit, 22;
2012 - 11 - 05, raccoon, 7;
2012 - 11 - 06, rabbit, 19;
2012 - 11 - 06, deer, 2;
2012 - 11 - 06, fox, 4;
2012 - 11 - 07, rabbit, 16;
2012 - 11 - 07, bear, 1;

She wants to write a shell script that takes a species as the first command-line argument and a directory as the second argument. The script should return one file called <species>.txt containing a list of dates and the number of that species seen on each date. For example using the data shown above, rabbit.txt would contain:

2012 - 11 - 05, 22;
2012 - 11 - 06, 19;
2012 - 11 - 07, 16;

Below, each line contains an individual command, or pipe. Arrange their sequence in one command in order to achieve Leah’s goal:

cut -d : -f 2
>
|
grep -w $1 -r $2
|
$1.txt
cut -d , -f 1,3
Exercise Criteria:
0 / 3
  • Script count-species.sh exists
  • Calling the script creates the file bear.txt: bash count-species.sh bear animal-counts/
  • The file bear.txt contains the list of dates and the number of bears seen
Hints:
Showing 0/2 hints
  • [Hint hidden]
  • [Hint hidden]
Loading...