Skip to content

Instantly share code, notes, and snippets.

@adunstan
Last active August 4, 2019 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adunstan/b1df3c7ee69eb6e9c68e2a156a0acd2d to your computer and use it in GitHub Desktop.
Save adunstan/b1df3c7ee69eb6e9c68e2a156a0acd2d to your computer and use it in GitHub Desktop.
obscure_strings
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
#############################################################################################
#
# 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