Skip to content

Instantly share code, notes, and snippets.

@Deleetdk
Created September 10, 2022 15:19
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 Deleetdk/868bc5a5849349a857a7d5841d6aa891 to your computer and use it in GitHub Desktop.
Save Deleetdk/868bc5a5849349a857a7d5841d6aa891 to your computer and use it in GitHub Desktop.
remove metadata linux with R
#!/usr/bin/env Rscript
library(stringr)
#scape spaces
escape_spaces = function(x) {
str_replace_all(x, fixed(" "), "\\ ")
}
#get args
args = commandArgs(trailingOnly=TRUE)
#escaped filename
escaped_filename = escape_spaces(args[1])
cat(escaped_filename)
#clean
#https://unix.stackexchange.com/questions/608593/removing-metadata-from-a-pdf
call1 = str_glue("exiftool -all:all= {escaped_filename}")
system(call1)
#linearize again
call2 = str_glue("qpdf --linearize {escaped_filename} 2{escaped_filename}")
system(call2)
#replace file back to orignal name
call3 = str_glue("mv 2{escaped_filename} {escaped_filename}")
system(call3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment