我有一个大文件,其中包含基于所用进程
和基准
案例数量的信息。所有这些信息都在同一个文件中一个接一个地出现。
--
# Benchmarking Allgather
# #processes = 8
# ( 3592 additional processes waiting in MPI_Barrier)
#----------------------------------------------------------------
#bytes #repetitions t_min[usec] t_max[usec] t_avg[usec]
0 1000 0.05 0.05 0.05
1 1000 1.77 2.07 1.97
2 1000 1.79 2.08 1.97
4 1000 1.79 2.07 1.98
8 1000 1.82 2.12 2.01
--
# Benchmarking Allgather
# #processes = 16
# ( 3584 additional processes waiting in MPI_Barrier)
#----------------------------------------------------------------
#bytes #repetitions t_min[usec] t_max[usec] t_avg[usec]
0 1000 0.05 0.05 0.05
1 1000 2.34 2.85 2.73
2 1000 2.36 2.87 2.74
4 1000 2.38 2.90 2.76
8 1000 2.42 2.95 2.79
为了快速绘制信息,我计划为每个独立内容创建一个文件,例如,根据上面给出的信息,我将创建两个名为“Allgather_8”和“Allgather_16”的文件,这些文件的预期内容将是:
$cat Allgather_8
#bytes #repetitions t_min[usec] t_max[usec] t_avg[usec]
0 1000 0.05 0.05 0.05
1 1000 1.77 2.07 1.97
2 1000 1.79 2.08 1.97
4 1000 1.79 2.07 1.98
8 1000 1.82 2.12 2.01
$cat Allgather_16
#bytes #repetitions t_min[usec] t_max[usec] t_avg[usec]
0 1000 0.05 0.05 0.05
1 1000 2.34 2.85 2.73
2 1000 2.36 2.87 2.74
4 1000 2.38 2.90 2.76
8 1000 2.42 2.95 2.79
然后我可以使用 gnuplot 或 matplotlib 绘制它。
到目前为止我尝试了什么:
我一直在使用 grep 和 awk 来提取内容,这适用于独立的部分,但我不知道如何自动执行此操作。
有什么想法吗?
最佳答案
awk '
/Benchmarking/ { close(out); out = $NF }
/#processes/ { out = out "_" $NF }
/^[[:space:]]/ { print > out }
' file
关于python - 从一个文件的提取内容创建文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44462845/