需要获取时间和特定值(如 "fcd<>",来自特定列的值)
Need to pick up the time and specific values (like "fcd<>", values from a specific column)
有一个带有时间和其他参数的大型原始文本文件。需要在第 5 列取时间、fcd0、fcd2 和 int 值。
文件中的示例内容
00:00:00
00:00:10 ciss0 23 1.16 76 5 71 0.03 1.13 1 0 28
fcd0 36 11.56 953 845 108 6.58 4.98 1 0 0
ciss4 23 1.16 76 4 72 0.03 1.13 1 0 27
fcd2 36 11.54 953 844 109 6.58 4.96 1 0 0
00:01:00
00:01:11 ciss0 13 0.31 37 0 37 0.00 0.31 1 0 31
fcd0 0 0.06 17 0 16 0.00 0.06 1 0 0
ciss4 13 0.29 37 1 36 0.00 0.29 1 0 31
fcd2 0 0.05 17 0 17 0.00 0.05 1 0 0
重要的部分是捕获所有订单项的时间。
output = []
with open('file.txt') as f:
for line in f:
values = re.split(r'\s+', line.strip(' \n'))
if len(values) > 1:
if ':' in values[0]:
time = values[0] # capture time for period till next time comes
if values[1] in ('fcd0', 'fcd2'):
output.append([time, values[1], int(values[6])])
else:
if values[0] in ('fcd0', 'fcd2'):
output.append([time, values[0], int(values[5])])
输出:
[['00:00:10', 'fcd0', 108],
['00:00:10', 'fcd2', 109],
['00:01:11', 'fcd0', 16],
['00:01:11', 'fcd2', 17]]
有一个带有时间和其他参数的大型原始文本文件。需要在第 5 列取时间、fcd0、fcd2 和 int 值。
文件中的示例内容
00:00:00
00:00:10 ciss0 23 1.16 76 5 71 0.03 1.13 1 0 28
fcd0 36 11.56 953 845 108 6.58 4.98 1 0 0
ciss4 23 1.16 76 4 72 0.03 1.13 1 0 27
fcd2 36 11.54 953 844 109 6.58 4.96 1 0 0
00:01:00
00:01:11 ciss0 13 0.31 37 0 37 0.00 0.31 1 0 31
fcd0 0 0.06 17 0 16 0.00 0.06 1 0 0
ciss4 13 0.29 37 1 36 0.00 0.29 1 0 31
fcd2 0 0.05 17 0 17 0.00 0.05 1 0 0
重要的部分是捕获所有订单项的时间。
output = []
with open('file.txt') as f:
for line in f:
values = re.split(r'\s+', line.strip(' \n'))
if len(values) > 1:
if ':' in values[0]:
time = values[0] # capture time for period till next time comes
if values[1] in ('fcd0', 'fcd2'):
output.append([time, values[1], int(values[6])])
else:
if values[0] in ('fcd0', 'fcd2'):
output.append([time, values[0], int(values[5])])
输出:
[['00:00:10', 'fcd0', 108],
['00:00:10', 'fcd2', 109],
['00:01:11', 'fcd0', 16],
['00:01:11', 'fcd2', 17]]