cs-3424: add solution to assignment 2

This commit is contained in:
Price Hiller 2024-07-14 17:44:41 -05:00
parent 533e9fd475
commit e671a3880c
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB
2 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,37 @@
#!/usr/bin/env bash
set -eEuo pipefail
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
replace_date_placeholders_in_file() {
local file="${1}"
local current_date
current_date="$(date +"%d\/%m\/%Y")"
sed -ri "s/(<dstamp>|<date>)/$current_date/g" "${file}"
}
replace_municipality_name_placeholders_in_file() {
local file="${1}"
local municipality_name="City of Brook Haven, Connecticut"
sed -ri "s/(<mname>|<muname>)/$municipality_name/g" "${file}"
}
redact_file() {
local file="${1}"
sed -ri -f "${SCRIPT_DIR}/assign2.sed" "${file}"
}
main() {
for file in "${@}"; do
redact_file "${file}"
replace_date_placeholders_in_file "${file}"
replace_municipality_name_placeholders_in_file "${file}"
done
}
main "${@}"

View File

@ -0,0 +1,15 @@
# Redact Driver's License numbers
s/[a-zA-Z]{2}\s?DL [0-9]{6,8}/DL <redacted>/g
# Redact Credit Card Numbers
## Visa Cards
s/4[0-9]{3}-?[0-9]{4}-?[0-9]{4}-?([0-9]{4})/VISA-\1/g
## Master Cards
s/5[0-9]{3}-?[0-9]{4}-?[0-9]{4}-?([0-9]{4})/MC-\1/g
## Discover Cards
s/6[0-9]{3}-?[0-9]{4}-?[0-9]{4}-?([0-9]{4})/DISC-\1/g
## Amex Cards (Important that it comes last because it collides inside larger card lengths)
s/3[47][0-9]{2}-?[0-9]{6}-?[0-9]([0-9]{4})/AMEX-\1/g
# Redact license plates
s/TX\s?[[:alnum:]]{3}-?([[:digit:]]{4}|[[:alnum:]]{3})/TX <redacted>/g