I have a query as below. It reads a text file into variable linn
. Line 2 (linn[2]
) and line 28 (linn[28]
) contain 2 dates (20160831;20160907). I would like to loop over a vector a
and copy each element at a time and replace those values on lines 2 and 8 and create a copy of the original file with only line 2 and line 8 changed. Then I would like to concatenate all the copies and write it into a txt file
How could I achieve the same?
#http://stackoverflow.com/questions/12626637/reading-a-text-file-in-r-line-by-line
fileName <- "C:/Users/500361/Downloads/query.txt"
conn <- file(fileName,open="r")
linn <-readLines(conn)
for (i in 1:length(linn)){
print(linn[i])
}
close(conn)
str(linn)
linn[2]
#[1] "<"department_code,department_desc,subclass_code,subclass_desc,dept_rank\" label=\"20160831;20160907\">"
linn[28]
#<sel value=\"between(date_id;20160831;20160907) [[ \\ text_req:From \\ text_req:To]] \"/>"
a=c("20160406;20160413","20160330;20160406")
a
update 1: updated values in line 2 and 28 will be
"<"department_code,department_desc,subclass_code,subclass_desc,dept_rank\" label=\"20160406;20160413\">"
#<sel value=\"between(date_id;20160406;20160413) [[ \\ text_req:From \\ text_req:To]] \"/>"
"<"department_code,department_desc,subclass_code,subclass_desc,dept_rank\" label=\"20160330;20160406\">"
#<sel value=\"between(date_id;20160330;20160406) [[ \\ text_req:From \\ text_req:To]] \"/>"