Skip to content

Instantly share code, notes, and snippets.

@MartinMSPedersen
Created February 12, 2021 12: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 MartinMSPedersen/78bf079be9c7da7ea0f813c67737ac08 to your computer and use it in GitHub Desktop.
Save MartinMSPedersen/78bf079be9c7da7ea0f813c67737ac08 to your computer and use it in GitHub Desktop.
Set difference
#!/usr/bin/env Rscript
args <- commandArgs(trailingOnly = TRUE)
if (length(args) < 2) {
cat("Usage: setdiff <file1> <file2> [files]\n", file = stderr())
}
ignorecase <- FALSE
if (args[[1]] == "-i") {
ignorecase <- TRUE
args <- args[-1]
}
if (ignorecase) {
set <- tolower(readLines(args[[1]]))
} else {
set <- readLines(args[[1]])
}
for (afile in args[-1]) {
if (ignorecase) {
set <- setdiff(set,tolower(readLines(afile)))
} else {
set <- setdiff(set,readLines(afile))
}
}
writeLines(set)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment