diff --git a/episodes/05-counting-mining.md b/episodes/05-counting-mining.md index 06433a97..c9c75d83 100644 --- a/episodes/05-counting-mining.md +++ b/episodes/05-counting-mining.md @@ -249,13 +249,17 @@ $ wc -l *.tsv | sort -n | head -n 1 | cat ## Count the number of words, sort and print (faded example) -To count the total lines in every `tsv` file, sort the results and then print the first line of the file we use the following: +As demonstrated above, the following commands pipe data from one to antoher to count the total lines in every `tsv` file, sort the results from smallest to largest (based on the first value in the line), then print the first line of the results to the display, thus showing the `tsv` file with the fewest lines: ```bash -wc -l *.tsv | sort -n | head -n 1 +$ wc -l *.tsv | sort -n | head -n 1 +``` + +```output + 5375 2014-02-02_JA-britain.tsv ``` -Now let's change the scenario. We want to know the 10 files that contain *the most* words. Check the manual for the `wc` command (either using `man wc` or `wc --help`) to see if you can find out what flag to use to print out the number of words (but not the number of lines and bytes). Fill in the blanks below to count the words for each file, put them into order, and then make an output of the 10 files with the most words (Hint: The sort command sorts in ascending order by default). +Now, let's change the scenario: instead of the number of lines in the files, which files contain the most *words*? Fill in the blanks below with the appropriate flags and commands so that the command pipeline will return the 10 files ordered from the lowest to highest word count. Check the manual for the `wc` command (either using `man wc` or `wc --help`) to see if you can find out what flag to use to print out the number of words (but not the number of lines and bytes). Fill in the blanks below to count the words for each file, put them into order, and then make an output of the 10 files with the most words (Hint: The sort command sorts in ascending order by default). ```bash wc __ *.tsv | sort __ | ____ @@ -265,7 +269,7 @@ wc __ *.tsv | sort __ | ____ ## Solution -Here we use the `wc` command with the `-w` (word) flag on all `tsv` files, `sort` them and then output the last 11 lines (10 files and the total) using the `tail` command. +Here we use the `wc` command with the `-w` (word) flag on all `tsv` files, `sort` them (in ascending order), and then output the last 11 lines (10 files and the total) using the `tail` command with the `-n 11` flag. ```bash wc -w *.tsv | sort -n | tail -n 11