提取 gnuplot 的日期时间和值

提取 gnuplot 的日期时间和值

我有以下输出,并尝试提取以下值:

日期 (X) 和值 (Y),每个数据点都标有步骤号。

这是输出:

Profiling step 1 @ 2016-08-31 11:58:56.344464+00:00 $1 170.58984375
Profiling step 2 @ 2016-08-31 12:02:10.958859+00:00 $2 3361.6328125
Profiling step 3 @ 2016-08-31 12:02:14.387444+00:00 $3 3361.0546875
Profiling step 4 @ 2016-08-31 12:03:53.674385+00:00 $4 4508.9765625
Profiling step 5 @ 2016-08-31 12:05:15.625707+00:00 $5 5487.6484375
Profiling step 6 @ 2016-08-31 12:05:24.167411+00:00 $6 5558.91796875
Profiling step 7 @ 2016-08-31 12:05:26.981129+00:00 $7 5582.12890625
Profiling step 8 @ 2016-08-31 12:05:30.468513+00:00 $8 5609.92578125
Profiling step 9 @ 2016-08-31 12:05:37.910140+00:00 $9 5673.94921875

到目前为止,我已经能够提取 $ 之后的步骤和值,例如。 1 170.589843 等,使用以下命令:

grep -o '$[^,]*'

输出:

$1 170.58984375
$2 3361.6328125
$3 3361.0546875
$4 4508.9765625
$5 5487.6484375
$6 5558.91796875
$7 5582.12890625
$8 5609.92578125
$9 5673.94921875

期望的输出:

2016-08-31 11:58:56.344464 170.58984375 1
2016-08-31 12:02:10.958859 3361.6328125 2
2016-08-31 12:02:14.387444 3361.0546875 3
etc..

有什么帮助吗?谢谢

答案1

$ awk '{sub(/[+-].*/,"",$6); print $5,$6,$8,$3}' file
2016-08-31 11:58:56.344464 170.58984375 1
2016-08-31 12:02:10.958859 3361.6328125 2
2016-08-31 12:02:14.387444 3361.0546875 3
2016-08-31 12:03:53.674385 4508.9765625 4
2016-08-31 12:05:15.625707 5487.6484375 5
2016-08-31 12:05:24.167411 5558.91796875 6
2016-08-31 12:05:26.981129 5582.12890625 7
2016-08-31 12:05:30.468513 5609.92578125 8
2016-08-31 12:05:37.910140 5673.94921875 9

sub只是修剪时区;如果不需要,可以忽略它)。

相关内容