Last active
April 20, 2020 15:19
-
-
Save wesley-dean/8c94aa164cb9c21957c5d7ec8657ef01 to your computer and use it in GitHub Desktop.
basic, generic sed script to sanitize things like AWS account numbers, IPv4 addresses, SSNs, TINs, etc. from text files, program output, etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env -S sed -Ef | |
# Replace 12-digit strings (AWS Account IDs) | |
# 123456789012 => 123********* | |
s/([^0-9])([0-9]{3})[0-9]{9}([^0-9])/\1\2*********\3/g | |
# Replace Social Security Numbers (SSNs) with dashes => | |
# 123-45-6789 => 123-**-**** | |
s/([^0-9])([0-9]{3})-([0-9]{2})-([0-9]{4})([^0-9])/\1\2-**-****\5/g | |
# Replace Taxpayer ID Numbers (TINs) containing dashes | |
# 12-3456789 => 12-******* | |
s/([^0-9])([0-9]{2})-([0-9]{2})[0-9]{5}([^0-9])/\1\2-\3*****\4/g | |
# Replace SSNs / TINs not containing dashes | |
# 123456789 => 123****** | |
s/(["'])([0-9]{3})([0-9]{9})\1/\1\2******\1/g | |
# Replace credit card numbers containing dashes | |
# 1234-5555-6666-7777 => 1234-****-****-**** | |
s/([^0-9]*)([0-9]{4})-([0-9]{4})-([0-9]{4})-([0-9]{4})([^0-9]*)/\1\2-****-****-****\6/g | |
# Replace IPv4 addresses | |
# 123.45.67.8 => 123.***.***.8 | |
s/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/\1.***.***.\4/g |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use: