Created
February 12, 2021 12:06
-
-
Save MartinMSPedersen/78bf079be9c7da7ea0f813c67737ac08 to your computer and use it in GitHub Desktop.
Set difference
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 | |
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