如何从文本文件中提取数据集?
How to extract data set from a text file?
我是 Unix 领域的新手,我目前正在尝试从文本文件中提取数据集。我尝试使用 sed、grep、awk,但它似乎只适用于提取行,但我想提取整个数据集...这是一个文件示例,我想从中提取 2 个数据集(后面的数字行 "R.Time Intensity")
[Header]
Application Name LabSolutions
Version 5.87
Data File Name C:\LabSolutions\Data\Antoine0921_AC_FluoSpectra9_WT3a derivatized lignin LiCl 430_GPC_FOREVER_430_049.lcd
Output Date 2017-10-12
Output Time 12:07:32
[Configuration]
Instrument Name BOTAN127-Instrument1
Instrument # 1
Line # 1
# of Detectors 3
Detector ID Detector A Detector B PDA
Detector Name Detector A Detector B PDA
# of Channels 1 1 2
[LC Chromatogram(Detector A-Ch1)]
Interval(msec) 500
# of Points 9603
Start Time(min) 0,000
End Time(min) 80,017
Intensity Units mV
Intensity Multiplier 0,001
Ex. Wavelength(nm) 405
Em. Wavelength(nm) 430
R.Time (min) Intensity
0,00000 -709779
0,00833 -709779
0,01667 17
0,02500 3
0,03333 7
0,04167 19
0,05000 9
0,05833 5
0,06667 2
0,07500 24
0,08333 48
[LC Chromatogram(Detector B-Ch1)]
Interval(msec) 500
# of Points 9603
Start Time(min) 0,000
End Time(min) 80,017
Intensity Units mV
Intensity Multiplier 0,001
R.Time (min) Intensity
0,00000 149
0,00833 149
0,01667 -1
如果有任何想法,我将不胜感激。提前致谢。
安托万
awk '/R.Time/,/LC/' file|grep -v -E "R.Time|LC"
grep 部分将删除作为 awk
输出的一部分的 R.Time 和 LC 行
awk '/^[^0-9]/&&d{d=0} /R.Time/{d=1}d' file
简要说明,
- 设置
d
作为标志来决定打印行与否
/^[^0-9]/&&d{d=0}
:如果正则表达式 ^[^0-9]
匹配 && d==1
,禁用 d
/R.Time/{d=1}
:如果搜索到字符串 "R.Time",则启用 d
我认为这是 sed 的工作。
sed '/R.Time/!d;:A;N;/\n$/!bA' infile
我是 Unix 领域的新手,我目前正在尝试从文本文件中提取数据集。我尝试使用 sed、grep、awk,但它似乎只适用于提取行,但我想提取整个数据集...这是一个文件示例,我想从中提取 2 个数据集(后面的数字行 "R.Time Intensity")
[Header]
Application Name LabSolutions
Version 5.87
Data File Name C:\LabSolutions\Data\Antoine0921_AC_FluoSpectra9_WT3a derivatized lignin LiCl 430_GPC_FOREVER_430_049.lcd
Output Date 2017-10-12
Output Time 12:07:32
[Configuration]
Instrument Name BOTAN127-Instrument1
Instrument # 1
Line # 1
# of Detectors 3
Detector ID Detector A Detector B PDA
Detector Name Detector A Detector B PDA
# of Channels 1 1 2
[LC Chromatogram(Detector A-Ch1)]
Interval(msec) 500
# of Points 9603
Start Time(min) 0,000
End Time(min) 80,017
Intensity Units mV
Intensity Multiplier 0,001
Ex. Wavelength(nm) 405
Em. Wavelength(nm) 430
R.Time (min) Intensity
0,00000 -709779
0,00833 -709779
0,01667 17
0,02500 3
0,03333 7
0,04167 19
0,05000 9
0,05833 5
0,06667 2
0,07500 24
0,08333 48
[LC Chromatogram(Detector B-Ch1)]
Interval(msec) 500
# of Points 9603
Start Time(min) 0,000
End Time(min) 80,017
Intensity Units mV
Intensity Multiplier 0,001
R.Time (min) Intensity
0,00000 149
0,00833 149
0,01667 -1
如果有任何想法,我将不胜感激。提前致谢。 安托万
awk '/R.Time/,/LC/' file|grep -v -E "R.Time|LC"
grep 部分将删除作为 awk
输出的一部分的 R.Time 和 LC 行awk '/^[^0-9]/&&d{d=0} /R.Time/{d=1}d' file
简要说明,
- 设置
d
作为标志来决定打印行与否 /^[^0-9]/&&d{d=0}
:如果正则表达式^[^0-9]
匹配 &&d==1
,禁用d
/R.Time/{d=1}
:如果搜索到字符串 "R.Time",则启用d
我认为这是 sed 的工作。
sed '/R.Time/!d;:A;N;/\n$/!bA' infile