Skip to content

Instantly share code, notes, and snippets.

@briatte
Created April 6, 2013 10:06
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 briatte/5325622 to your computer and use it in GitHub Desktop.
Save briatte/5325622 to your computer and use it in GitHub Desktop.
find credit card information on your disk files (by Jeroen Ooms, arXiv:1303.4808v2)
findCreditCards <- function() {
pattern <- "([0-9]{4}[- ]){3}[0-9]{4}"
path <- "~/Documents"
filelist <- list.files(path, full.names=TRUE, recursive=TRUE)
for (filename in filelist){
if(file.info(filename)$size > 1e6) next
doc <- readLines(filename)
results <- gregexpr(pattern, doc)
output <- unlist(regmatches(doc, results))
if(length(output) > 0){
cat(paste(filename, ":", output,
collapse="\n"), "\n")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment