This Is Not The Course Website You Are Looking For

This course website is from a previous semester. If you are currently in the class, please make sure you are viewing the latest course website instead of this old one.


Next week, we will continue to explore shell scripting. This time, however, we will unlock the true power of the Unix philosophy by studying sophisticated pipelines for filtering text. Additionally, we will also learn to wield regular expressions to create nifty pattern matching tools.


The focus of this reading is to introduce regular expressions and revisit filters and pipelines.


The readings for this week are:

  1. The Linux Command Line:

    • Chapter 19 - Regular Expressions
    • Chapter 20 - Text Processing
  2. RegexOne

    Work through the Lessons in the Interactive Tutorial. You can use the Regexpr to visualize your regular expressions.

Optional Resources


This week, your reading quiz is split into two sections: the first part is your normal dredd quiz, while the second part involves a series of pipelines.


Record the answers to the following Reading 03 Quiz questions in your reading03 branch:


For the second part, you are to complete the following pipelines:

  1. Convert all the input text to upper case:

    $ echo "Read the fine manual" | ...
  2. Find and replace all instances of Arch with Pop:

    $ echo "BTW, I use Arch" | ...
    BTW, I use Pop
  3. Remove any leading whitespace from a string of text:

    $ echo "     Yes, do as I say" | ...
    Yes, do as I say
  4. Parse the /etc/passwd file for the shell of the root user:

    $ curl -sL | ...

    Hint: You may need to read up on the format of /etc/passwd

  5. Find all the records in /etc/passwd that have a number that begins with a 4 and ends with a 7:

    $ curl -sL | ...
    qpidd:x:497:495:Owner of Qpidd Daemons:/var/lib/qpidd:/sbin/nologin
    uuidd:x:495:487:UUID generator helper daemon:/var/lib/libuuid:/sbin/nologin
  6. Find and replace all instances of /bin/sh, /bin/bash, /bin/csh, and /bin/tcsh to /bin/zsh in /etc/passwd:

    $ curl -sL | ... | grep zsh
    mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/zsh
    condor:x:108172:40:Condor Batch System:/afs/


To record your pipelines, you will need to write your answers to the script:

# Download filters template
$ curl -LO

Each question has a corresponding function; for instance, the solution for Question 1 should be recorded in q1_answer:


q1_answer() {
    # TODO: Complete pipeline
    echo "Read the fine manual" | ...

To construct your pipelines, you should try them interactively in your shell. Once you found a reasonable solution, you can record them in the script under the appropriate function.


To test your pipelines, you need to download the Reading 03 Makefile, which in turn will download the test script and execute it:

# Download Makefile
$ curl -LO

# Download test scripts and run test
$ make

# Check your filters
$ ./
Checking reading03 ...
      Q1 Success
      Q2 Success
      Q3 Success
      Q4 Success
      Q5 Success
      Q6 Success
   Score 3.00 / 3.00
  Status Success


To submit your work, follow the same process outlined in Reading 01:

$ git checkout master                 # Make sure we are in master branch
$ git pull --rebase                   # Make sure we are up-to-date with GitHub

$ git checkout -b reading03           # Create reading03 branch and check it out

$ cd reading03                        # Go into reading03 folder
$ $EDITOR answers.json                # Edit your answers.json file

$ ../.scripts/                # Check reading03 quiz
Checking reading03 quiz ...
      Q1 1.00
   Score 1.00 / 1.00
  Status Success

$ git add answers.json                # Add answers.json to staging area
$ git commit -m "Reading 03: Quiz"    # Commit work

$ $EDITOR                  # Edit your file

$ ./                   # Check your filters
Checking reading03 ...
      Q1 Success
      Q2 Success
      Q3 Success
      Q4 Success
      Q5 Success
      Q6 Success
   Score 3.00 / 3.00
  Status Success

$ git add Makefile                    # Add Makefile to staging area
$ git add                  # Add to staging area
$ git commit -m "Reading 03: Filters" # Commit work

$ git push -u origin reading03        # Push branch to GitHub

Pull Request

Remember to create a Pull Request and assign the appropriate TA from the Reading 03 TA List.

DO NOT MERGE your own Pull Request. The TAs use open Pull Requests to keep track of which assignments to grade. Closing them yourself will cause a delay in grading and confuse the TAs.