Homework 7

More regex and sed

This assignment involves writing regex replacements with sed to automate changes in a codebase and interact with a git repository.

Updating your faang repository

Like most assignments, you will submit a task1.sh file to Gradescope. Unlike most assignments, you will obtain this task1.sh file by updating your faang repository main branch. To do this, either run git pull in the repository:

git checkout main
git pull

Or, if you run into issues, re-clone the repository from scratch.

git clone git@gitlab.cs.washington.edu:cse391/25wi/faang.git

You know that you have an up-to-date version if the task1.sh has the appropriate quarter in its header.

Task 1: Regex replacements with sed

We’ll continue our work at faang, which is now in the process of rebranding as “24AndMe”, a biotech marketplace. For this task, assume all commands are run in the root of the repository. Several of these commands involve updating files in-place: to revert your changes, use git commands to discard your unstaged changes.

  1. Write a sed command that replaces the string Insert Catchy Slogan Here in Build.java with any non-empty slogan of your preference. This command should update the file in-place.
  2. Write a sed command that replaces all occurrences of dirt (case-insensitively) in Build.java with the string soil. This command should update the file in-place.
  3. Write a sed command that ensures all product prices in Build.java contain cent values without modifying product prices that already contain cent values. A price of $0.01 should remain $0.01 while a price of $priceless should become $priceless.00. This command should update the file in-place.
  4. Write a sed command that reformats each credit card number in cards.txt to have consistent spacing, where each group of 4 numbers is separated by a single space, and the last group of numbers contains 1-4 characters. This command should not modify cards.txt.
  5. Write a sed command that replaces all occurrences of FAANG (case-insensitively) to 24AndMe across all regular (non-hidden) files in the repository. This command should update all files in-place.
  6. Write a command beginning git log | that creates an authors.txt file containing an alphabetically-sorted list of all unique git log authors. An author is all the text that appears after Author: in the git log. Authors with the same name but different emails should be considered distinct. Authors should be compared and sorted case-insensitively.
  7. Write a command that prints a list of the unique name for each author from authors.txt assuming that each author is a row formatted name <email>. Be sure to remove duplicates during this process, and ensure the name does not include the space separating the name from the email.
  8. Write a command that prints a list of the unique username@24AndMe.com emails for each author from authors.txt. In this problem, a username is any non-whitespace character that comes before the @ symbol in the email address: assume all authors have corresponding work email addresses at 24AndMe.com. Be sure to remove duplicates during this process.