Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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