Readings

This week the readings will focus on regular expressions and filters. These additional tools will come in handy when we want to write more advanced shell scripts that slice and dice data.

The readings for Monday, February 22 are:

  1. regular expressions:

  2. filters:

Optional Resources:

  1. Digital Ocean Tutorials:

  2. Advanced Bash Scripting - Text Processing Commands

  3. The Unix School - Awk & Sed

  4. Sed - An Introduction and Tutorial

    Also Grep - An introduction to grep and egrep

  5. USEFUL ONE-LINE SCRIPTS FOR SED

  6. sed command 20 practical examples

Questions

In your reading06/README.md file, describe what command(s) you would use to accomplish the following:

  1. Convert all the input text to upper case:

    $ echo "All your base are belong to us" | ...
    ALL YOUR BASE ARE BELONG TO US
    
  2. Parse the /etc/passwd file for the shell of the root user:

    $ cat /etc/passwd | ...
    /bin/bash
    

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

  3. Find and replace all instances of monkeys to gorillaz:

    $ echo "monkeys love bananas" | ...
    gorillaz love bananas
    
  4. Find and replace all instances of /bin/bash, /bin/csh, and /bin/tcsh to /usr/bin/python in /etc/passwd:

    $ cat /etc/passwd | ... | grep python
    root:x:0:0:root:/root:/usr/bin/python
    mysql:x:27:27:MySQL Server:/var/lib/mysql:/usr/bin/python
    xguest:x:500:501:Guest:/home/xguest:/usr/bin/python
    condor:x:108172:40:Condor Batch System:/afs/nd.edu/user37/condor:/usr/bin/python
    lukew:x:522:40:Luke Westby temp access:/var/tmp/lukew:/usr/bin/python
    
  5. Remove any leading whitespace from a string of text:

    $ echo "     monkeys love bananas" | ...
    monkeys love bananas
    
  6. Find all the records in /etc/passwd that have a number that begins with a 4 and ends with a 7:

    $ cat /etc/passwd | ...
    rtkit:x:499:497:RealtimeKit:/proc:/sbin/nologin
    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
    mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin
    
  7. Follow the trailing output of a set of log files.

  8. Given two files, show all the lines the are present in both files.

Commands

In the reading06 folder, write at least five summary pages for the following commands:

  1. cut

  2. sort

  3. comm

  4. uniq

  5. paste

  6. tr

  7. grep

  8. sed

  9. head

  10. tail

Summaries

Note, your summaries should be in your own words and not simply copy and pasted from the manual pages. They should be short and concise and only include common use cases.

Feedback

If you have any questions, comments, or concerns regarding the course, please provide your feedback at the end of your response.

Submission

To submit your assignment, please commit your work to the reading06 folder in your Assignments Bitbucket repository by the beginning of class on Monday, February 22.