-
-
Notifications
You must be signed in to change notification settings - Fork 966
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add solution to 07 'tracking a species'
Add new directory and file to contain example data shown. Update zip archive to contain new file and directory.
- Loading branch information
Showing
3 changed files
with
29 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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} | ||
> | ||
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
gcapes
Author
Contributor
|
||
> > ``` | ||
> > {: .source} | ||
> > | ||
> > You would call the script above like this: | ||
> > | ||
> > ``` | ||
> > $ bash count-species.sh bear . | ||
> > ``` | ||
> > {: .bash} | ||
> {: .solution} | ||
{: .challenge} | ||
|
||
> ## Little Women | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
What is the first cut doing in this line? There are no columns delimited by ':'.