I have multiple text files stored in different folders. The structure of data stored in each .txt file is the same. Each text file starts with some information and 5th line forward, the file has a sign */ after which data starts. The file appears as follows:
*/
Date AirTemp Pres Wind ....
2021-03-01 27 1017 10....
2021-03-02.....
I want to read only the data in these .txt files and not information stored prior to */. For this, I am using the following code in R where I am commanding to consider */ as the last line before the actual data starts.
setwd("D:/Test")
library(stringr)
con <- file("D:/Test/Data1.txt", "r")
lines <- c()
while(TRUE) {
line = readLines(con, 1)
if(length(line) == 0) break
else if(grepl("^\\s*/{1}", line)) lines <- c(lines, line)
}
On running the code, it is not returning me anything and 'lines' appear to be empty. Could anyone help me with this.