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
sed
command that replaces the stringInsert Catchy Slogan Here
inBuild.java
with any non-empty slogan of your preference. This command should update the file in-place. - Write a
sed
command that replaces all occurrences ofdirt
(case-insensitively) inBuild.java
with the stringsoil
. This command should update the file in-place. - Write a
sed
command that ensures all product prices inBuild.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. - Write a
sed
command that reformats each credit card number incards.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 modifycards.txt
. - Write a
sed
command that replaces all occurrences ofFAANG
(case-insensitively) to24AndMe
across 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.txt
file containing an alphabetically-sorted list of all uniquegit log
authors. 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
name
for each author fromauthors.txt
assuming 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.com
emails for each author fromauthors.txt
. In this problem, ausername
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.