I have a question about extracting a part of a string from several files that has these rows:
units = specified - name 0 = prDM: Pressure, Digiquartz [db] - name 1 = t090C: Temperature [ITS-90, deg C] - name 2 = c0S/m: Conductivity [S/m] - name 3 = t190C:Temperature, 2 [ITS-90, deg C] - name 4 = c1S/m: Conductivity, 2 [S/m] - name 5 = flSP: Fluorescence, Seapoint - name 6 = sbeox0ML/L: Oxygen, SBE 43 [ml/l] - name 7 = altM: Altimeter [m] - name 8 = sal00: Salinity, Practical [PSU] - name 9 = sal11: Salinity, Practical, 2 [PSU] - span 0 = 1.000, 42.000
I need to extract only the information of the columns that start with "name" and extract everything between = and: . For example, in the row "name 0 = prDM: Pressure, Digiquartz [db]" the desired result will be prDM. Some files have different number of "name"rows (i.e. this example has 13 rows but other files has 16, and the number varies), so I want it to be as general as I can so I can allways extract the right strings independently the number of rows.Rows starts with # and a space before name. I have tried this code but it only extract the first row. Can you please help me with this? Many thanks!
CNV<-NULL
for (i in 1:nro.files){
x <- readLines(all.files[i])
name.col<-grep("^\\# name", x)
df <- data.table::fread(text = x[name.col])
CNV[[i]]<-df
}