Unix Commands  «Prev  Next»

–c option grep - Exercise

The –c option to grep

Objective:Practice writing regular expressions and grep commands

Exercise scoring

This exercise is worth 5 points and is auto-scored.


  1. 1. Access the clothes file located in your home directory.
  2. 2. Write a grep command to list lines containing Black in the clothes file.
  3. 3. Write a command to count the number of lines containing the string “pair of shoes” in the clothes file.
  4. 4. Write an assignment statement to save the output of the previous command in a variable called count. Use embedded command execution.
    First, run the command below to create a variable called item.
    $ item=”pair of shoes” 
  5. 5. Then, write an assignment statement to create a variable called itemcount. This variable will store the number of lines matching “pair of shoes” in the clothes file. Use embedded command execution.