Skip to content

Instantly share code, notes, and snippets.

@gabriel-fallen
Created January 17, 2020 17:35
Show Gist options
  • Save gabriel-fallen/3210ec12b43c1c42a052ec79c3cc5c27 to your computer and use it in GitHub Desktop.
Save gabriel-fallen/3210ec12b43c1c42a052ec79c3cc5c27 to your computer and use it in GitHub Desktop.
Simple R script for filtering file names without associated output for my particular setup.
#! /usr/bin/env Rscript
input_con <- file("stdin")
open(input_con)
prevLine <- ""
while (length(curLine <- readLines(con = input_con,
n = 1,
warn = FALSE)) > 0) {
if (length(grep("^/home/[^:]+:$", curLine)) > 0) {
prevLine <- curLine
} else if (nchar(prevLine) > 0) {
if (nchar(curLine) == 0) {
prevLine <- "" # exlude both from output and reset state
} else {
writeLines(c(prevLine, curLine))
prevLine <- ""
}
} else {
writeLines(curLine)
}
}
close(input_con)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment