Terminal Exercises
Help 11 / 25
Pipes and Filters

Pipe construction

First, go to the animal-counts folder:

cd $TUTORIAL/exercise-data/animal-counts
ls -l

For the file animals.csv, consider the following command:

cut -d , -f 2 animals.csv

The cut command is used to remove or ‘cut out’ certain sections of each line in the file, and cut expects the lines to be separated into columns by a Tab character. A character used in this way is a called a delimiter. In the example above we use the -d option to specify the comma as our delimiter character. We have also used the -f option to specify that we want to extract the second field (column).

The uniq command filters out adjacent matching lines in a file. How could you extend this pipeline (using uniq and another command) to find out what animals the file contains (without any duplicates in their names)?

Store the result in unique.csv:

Exercise Criteria:
0 / 2
  • File unique.csv exists
  • File unique.csv contains the unique rows from the file animals.csv
Loading...