Created
September 10, 2022 15:19
-
-
Save Deleetdk/868bc5a5849349a857a7d5841d6aa891 to your computer and use it in GitHub Desktop.
remove metadata linux with R
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 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