Created
January 17, 2020 17:35
-
-
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.
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 | |
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