Skip to content

Commit 51b1009

Browse files
authored
Merge pull request #148 from scottcpeterson/patch-12
Counting number of files part I and II exercises are a bit misleading…
2 parents 62c1b7c + ffd55c8 commit 51b1009

File tree

1 file changed

+2
-45
lines changed

1 file changed

+2
-45
lines changed

_episodes/05-counting-mining.md

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -331,20 +331,13 @@ programming languages.
331331
> ## Counting number of files
332332
> Let's make a different pipeline. You want to find out how many files and
333333
> directories there are in the current directory. Try to see if you can pipe
334-
> the output from `ls` into `wc` to find the answer, or something close to the
335-
> answer.
334+
> the output from `ls` into `wc` to find the answer.
336335
>
337336
> > ## Solution
338-
> > You get close with
339-
> >
340337
> > ~~~
341-
> > $ ls -l | wc -l
338+
> > $ ls | wc -l
342339
> > ~~~~
343340
> > {: .bash}
344-
> >
345-
> > but the count will be one too high, since the "total" line from `ls`
346-
> > is included in the count. We'll get back to a way to fix that later
347-
> > when we've learned about the `grep` command.
348341
> {: .solution}
349342
{: .challenge}
350343
@@ -754,42 +747,6 @@ Pair up with your neighbor and work on these exercises:
754747
> {: .solution}
755748
{: .challenge}
756749
757-
> ## Counting number of files, part II
758-
> In the earlier counting exercise in this episode, you tried counting the number
759-
> of files and directories in the current directory.
760-
>
761-
> * Recall that the command `ls -l | wc -l` took us quite far, but the result was one
762-
> too high because it included the "total" line in the line count.
763-
> * With the knowledge of `grep`, can you figure out how to exclude the "total"
764-
> line from the `ls -l` output?
765-
> * Hint: You want to exclude any line *starting*
766-
> with the text "total". The hat character (^) is used
767-
> in regular expressions to indicate the start of a line.
768-
>
769-
> > ## Solution
770-
> > To find any lines starting with "total", we would use:
771-
> >
772-
> > ~~~
773-
> > $ ls -l | grep -E '^total'
774-
> > ~~~
775-
> > {: .bash}
776-
> >
777-
> > To *exclude those lines, we add the `-v` flag:
778-
> >
779-
> > ~~~
780-
> > $ ls -l | grep -v -E '^total'
781-
> > ~~~
782-
> > {: .bash}
783-
> >
784-
> > The grand finale is to pipe this into `wc -l`:
785-
> >
786-
> > ~~~
787-
> > $ ls -l | grep -v -E '^total' | wc -l
788-
> > ~~~
789-
> > {: .bash}
790-
> {: .solution}
791-
{: .challenge}
792-
793750
### Using a Loop to Count Words
794751
795752
We will now use a loop to automate the counting of certain words within a document. For this, we will be using the _[Little Women](http://www.gutenberg.org/cache/epub/514/pg514.txt)_ e-book from [Project Gutenberg](https://www.gutenberg.org/). The file is inside the `shell-lesson` folder and named `pg514.txt`. Let's rename the file to `littlewomen.txt`.

0 commit comments

Comments
 (0)