我有一个看起来像这样的文件:
$cat myfile.dat
Number of reps: nrep= 19230
flop count: nops= 4725964800.
Clock resolution is 4.7619047619047619E-4 , usecs
time = 7.18247611075639725E-6
calc 0: time= 2.902 Gflop/s= 1.629 error= 0.00000000
calc 201: time= 1.186 Gflop/s= 3.985 error= 0.00000000
Number of reps: nrep= 13456
flop count: nops= 4234564800.
Clock resolution is 3.7619047619047619E-4 , usecs
time = 7.18247611075639725E-6
calc 0: time= 1.232 Gflop/s= 2.456 error= 0.00000000
calc 201: time= 3.186 Gflop/s= 1.345 error= 0.00000000
我有兴趣过滤我需要的东西:nrep
、time
和 Gflop/s
但这最后两个只是开始的行使用 calc 201
。
到目前为止,除了元素 time
和 Gflop/s
之外,我已经设法过滤了我想要的内容。这就是我所做的:
awk -F'= ?' '/nrep=/||/time=/||/Gflop/{print $2}' myfile.dat
19230
2.902 Gflop/s
1.186 Gflop/s
13456
1.232 Gflop/s
3.186 Gflop/s
这显然是错误的。我需要的,最好是在列中:
19230 1.186 3.985
13456 3.186 1.345
有没有合理的方法来做到这一点?
最佳答案
使用 GNU awk
你只需要做:
$ awk 'NR>1{print $2,$27,$29}' RS='Number of reps:' file
19230 1.186 3.985
13456 3.186 1.345
关于bash - 使用 AWK 递归查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18163954/