Skip to content

Commit

Permalink
Add solution to 07 'tracking a species'
Browse files Browse the repository at this point in the history
Add new directory and file to contain example data shown.
Update zip archive to contain new file and directory.
  • Loading branch information
gcapes committed Feb 27, 2017
1 parent 22c7745 commit 0b83da0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
26 changes: 21 additions & 5 deletions _episodes/07-find.md
Original file line number Diff line number Diff line change
Expand Up @@ -567,15 +567,14 @@ about them."
> ~~~
> {: .source}
>
> She wants to write a shell script that takes a directory and a species
> as command-line parameters and return one file called `species.txt`
> containing a list of dates and the number of that species seen on that date,
> such as this file for rabbits:
> 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, `rabbits.txt` would contain:
>
> ~~~
> 2013-11-05,22
> 2013-11-06,19
> 2013-11-07,18
> ~~~
> {: .source}
>
Expand All @@ -594,6 +593,23 @@ about them."
>
> Hint: use `man grep` to look for how to grep text recursively in a directory
> and `man cut` to select more than one field in a line.
>
> An example of such a file is provided in `data-shell/data/animal-counts/animals.txt`
>
> > ## Solution
> >
> > ```
> > grep -w $1 -r $2 | cut -d : -f 2 | cut -d , -f 1,3 > $1.txt

This comment has been minimized.

Copy link
@dacb

dacb Jun 29, 2017

What is the first cut doing in this line? There are no columns delimited by ':'.

This comment has been minimized.

Copy link
@gcapes

gcapes Jun 30, 2017

Author Contributor

There is a colon in the grep output. Try adding each section of the pipeline one at a time and view the output in each case.

> > ```
> > {: .source}
> >
> > You would call the script above like this:
> >
> > ```
> > $ bash count-species.sh bear .
> > ```
> > {: .bash}
> {: .solution}
{: .challenge}

> ## Little Women
Expand Down
8 changes: 8 additions & 0 deletions data-shell/data/animal-counts/animals.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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
Binary file modified data/shell-novice-data.zip
Binary file not shown.

0 comments on commit 0b83da0

Please sign in to comment.