Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created December 9, 2024 09:52
Show Gist options
  • Save abikoushi/9e624797da9afe929fe37de4f81a5521 to your computer and use it in GitHub Desktop.
Save abikoushi/9e624797da9afe929fe37de4f81a5521 to your computer and use it in GitHub Desktop.
Run AWK query from R (change specific rows)
query_awk <- function(vpar, pdir, filename, uid){
chl <- paste0("cat ", pdir, "/", filename)
for(i in 1:nrow(vpar)){
chr <- paste0("\"", paste(vpar[i,], collapse = ", "), "\"")
awk <- paste0(" | awk 'NR==", uid[i], "{sub('/.*/',", chr, ")}1'")
chl <- paste0(chl, awk)
}
chl <- paste0(chl, " > ", pdir, "/tmp.csv")
mvit <- paste0("mv ", pdir, "/tmp.csv " , pdir, "/", filename)
system(chl)
system(mvit)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment