Last active
August 4, 2019 13:57
-
-
Save adunstan/b1df3c7ee69eb6e9c68e2a156a0acd2d to your computer and use it in GitHub Desktop.
obscure_strings
This file contains hidden or 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
perl -p -e "local \$/ = undef; my \$log = <>; \$log =~ s/('|\\\$[a-zA-Z0-9_]*\\\$)(.*)\$1/\$1 . (q[X] x length(\$2)) . \$1/gme; print \$log;" /tmp/logsamp |
This file contains hidden or 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
############################################################################################# | |
# | |
# scrub strings in a postgres log file | |
# | |
# this script is not guarabnteed to work in all cases, but it will work in a great many. | |
# | |
# The theory is that if the strings are scrubbed the file is sufficiently anonymous to | |
# be able to share it with consultants etc. safely. | |
# | |
############################################################################################ | |
local $/ = undef; | |
my $log = <>; | |
foreach ($log) | |
{ | |
s/(\$[a-zA-Z0-9_]*\$)(.*?)\1/$1 . 'X' x length($2) . $1/gse; # dollar quotes | |
# should eliminate the case of an e before the terminating quote of a non-E'' quote | |
s/(?<![eE])'((''|[^'])*?)'/"'" . 'X' x length($1) . "'"/gse; # non E'' others | |
s/[Ee]'((\\.|[^'])*?)'/"E'" . 'X' x length($1) . "'"/gse; # E'' quotes | |
} | |
print $log; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment