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.
- Write a
sedcommand that replaces the stringInsert Catchy Slogan HereinBuild.javawith any non-empty slogan of your preference. This command should update the file in-place. - Write a
sedcommand that replaces all occurrences ofdirt(case-insensitively) inBuild.javawith the stringsoil. This command should update the file in-place. - Write a
sedcommand that ensures all product prices inBuild.javacontain cent values without modifying product prices that already contain cent values. A price of$0.01should remain$0.01while a price ofpricelessshould becomepriceless.00. This command should update the file in-place. While your final submission should not use the$literal in your regex, if you would like to get feedback with regexes including$, be sure to double-escape it in your submission with\\$so thatsedreceives both the backslash and the dollar sign. - Write a
sedcommand that reformats each credit card number incards.txtto 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 modifycards.txt. - Write a
sedcommand that replaces all occurrences ofFAANG(case-insensitively) to24AndMeacross all regular (non-hidden) files in the repository. This command should update all files in-place. - Write a command beginning
git log |that creates anauthors.txtfile containing an alphabetically-sorted list of all uniquegit logauthors. An author is all the text that appears afterAuthor:in thegit log. Authors with the same name but different emails should be considered distinct. Authors should be compared and sorted case-insensitively. - Write a command that prints a list of the unique
namefor each author fromauthors.txtassuming that each author is a row formattedname <email>. Be sure to remove duplicates during this process, and ensure the name does not include the space separating the name from the email. - Write a command that prints a list of the unique
username@24AndMe.comemails for each author fromauthors.txt. In this problem, ausernameis 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.