From 3c8b886b095d9892b2c49c37771888d7b9e7132e Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Sun, 14 Jul 2024 17:44:41 -0500 Subject: [PATCH] cs-3424: add solution to assignment 2 --- .../Assignments/Assignment-2/src/assign2.bash | 34 +++++++++++++++++++ .../Assignments/Assignment-2/src/assign2.sed | 15 ++++++++ 2 files changed, 49 insertions(+) create mode 100755 Summer-2024/CS-3424/Assignments/Assignment-2/src/assign2.bash create mode 100644 Summer-2024/CS-3424/Assignments/Assignment-2/src/assign2.sed diff --git a/Summer-2024/CS-3424/Assignments/Assignment-2/src/assign2.bash b/Summer-2024/CS-3424/Assignments/Assignment-2/src/assign2.bash new file mode 100755 index 0000000..2ae48a1 --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-2/src/assign2.bash @@ -0,0 +1,34 @@ +#!/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/(|)/$current_date/g" "$file" + +} + +replace_municipality_name_placeholders_in_file() { + local file="${1}" + local municipality_name="City of Brook Haven, Connecticut" + sed -ri "s/(|)/$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 "${@}" diff --git a/Summer-2024/CS-3424/Assignments/Assignment-2/src/assign2.sed b/Summer-2024/CS-3424/Assignments/Assignment-2/src/assign2.sed new file mode 100644 index 0000000..846bc05 --- /dev/null +++ b/Summer-2024/CS-3424/Assignments/Assignment-2/src/assign2.sed @@ -0,0 +1,15 @@ +# Redact Driver's License numbers +s/[a-zA-Z]{2}\s?DL [0-9]{6,8}/DL /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 /g