cs-3424: add solution to assignment 2
This commit is contained in:
parent
533e9fd475
commit
3c8b886b09
34
Summer-2024/CS-3424/Assignments/Assignment-2/src/assign2.bash
Executable file
34
Summer-2024/CS-3424/Assignments/Assignment-2/src/assign2.bash
Executable file
@ -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/(<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 "${@}"
|
15
Summer-2024/CS-3424/Assignments/Assignment-2/src/assign2.sed
Normal file
15
Summer-2024/CS-3424/Assignments/Assignment-2/src/assign2.sed
Normal 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
|
Loading…
x
Reference in New Issue
Block a user