I have a text file of the following format: //
DATASET
..... unnecessary lines.....
TIMEUNITS SECONDS
TS 0 1.98849600e+08
3.30000000e-03 1.25400000e-02 5.88000000e-03 0.00000000e+00 0.00000000e+00
5.88000000e-03 3.33000000e-03 2.16000000e-03 0.00000000e+00 0.00000000e+00
TS 0 1.98853209e+08
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
1.25400000e-02 5.88000000e-03 3.33000000e-03 0.00000000e+00 0.00000000e+00
TS 0 1.98860419e+08
3.33000000e-03 2.16000000e-03 1.08000000e-03 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
TS 0 1.98864081e+08
1.08000000e-03 8.70000000e-04 7.20000000e-04 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
TS 0 1.98867619e+08
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
3.33000000e-03 2.16000000e-03 1.08000000e-03 0.00000000e+00 0.00000000e+00
I am also attaching the sample text file named "D50.bc" in this link: https://drive.google.com/file/d/1P5aFC0JsRLhwuUo7JENLg03DbDJ696lk/view?usp=sharing.
There is no column names but it is fine to add column names i.e., V1, V2 etc. In the real text file there are 14 columns and 1000s of lines/rows after each TS. Each row corresponds to a node and the columns corresponds to certain values(i.e., velocity/shear stress etc.) at that node
I want to extract all the data/tables under the lines "TS 0 XXX" into individual dfs based on their timestamps(TS) so that I can do column operations for each TS. The TS value XXXX which is in second can be added as a separate column in the dfs. Below is the regular expression I have tried in R but it returns nothing. Any help is highly appreciated.
library(dplyr)
rm(list=ls(all=TRUE))
a <- paste0(readLines("D:/D50 python/D50.bc"), collapse = "\n")
b <- regmatches(a, gregexpr("(?s)^TS[^\n]+0.*?\n\\K.*?\n\b", a,, perl = T))[[1]]