Solutions

Using grep

The correct answer is 3, because the -w flag looks only for whole-word matches. The other options will all match "of" when part of another word.

Tracking a Species

grep -w $1 -r $2 | cut -d : -f 2 | cut -d , -f 1,3  > $1.txt

You would call the script above like this:

bash count-species.sh bear .

.

Little Women

grep -ow Amy LittleWomen.txt | wc -l
grep -ow Beth LittleWomen.txt | wc -l
grep -ow Jo LittleWomen.txt | wc -l
grep -ow Meg LittleWomen.txt | wc -l

Alternative, slightly inferior solution:

grep -ocw Amy LittleWomen.txt
grep -ocw Beth LittleWomen.txt
grep -ocw Jo LittleWomen.txt
grep -ocw Meg LittleWomen.txt

This solution is inferior because grep -c only reports the number of lines matched. The total number of matches reported by this method will be lower if there is more than one match per line.

Matching and Subtracting

The correct answer is 1. Putting the match expression in quotes prevents the shell expanding it, so it gets passed to the find command.

Option 2 is incorrect because the shell expands *s.txt instead of passing the wildcard expression to find.

Option 3 is incorrect because it searches the contents of the files for lines which do not match "temp", rather than searching the file names.

find Pipeline Reading Comprehension

  1. Find all files with a .dat extension in the current directory
  2. Count the number of lines each of these files contains
  3. Sort the output from step 2. numerically

Finding Files With Different Properties

Assuming that Nelle's home is our working directory we type:

find ./ -type f -mtime -1 -user ahmed

.