我有来自CFD模拟的输出Residuals文件。文件以文本开头,然后显示数值。数值数据是每次迭代时迭代和不同变量值的集合。但是在每行迭代之间我都有文本。我想只读取数值。最后,在最后一次迭代后,我有一些我不想要的文本。我怎么能用“grep”或“awk”来实现这一点?
Conjugate-Gradient solver did not converge !
Iteration Continuity X-momentum Y-momentum Z-momentum Energy Tke Sdr Intermittency Heat Transfer 1 (W) Pinlet (Pa) T_outlet (K) twallFroide (K) surf_avg_q_crit (/s^2) Maximum tempfroide (K) Surface Average Helicity (/s)
1 1.851301e-09 1.213569e-07 2.692437e-09 4.273490e-10 1.888124e-03 3.166891e-07 5.527057e-06 1.418467e-23 -9.974981e+00 2.505598e+03 2.900000e+02 4.000053e+02 -1.627486e+06 4.000053e+02 9.216386e+03
Conjugate-Gradient solver did not converge !
2 1.506520e-09 6.493389e-08 1.170308e-08 1.013586e-08 3.910613e-04 1.808261e-08 1.438014e+00 8.318085e-08 -9.193516e+00 3.435342e+03 2.899868e+02 4.000056e+02 -3.203329e+05 4.000056e+02 1.100795e+04
Conjugate-Gradient solver did not converge !
3 1.525969e-09 3.735938e-08 6.075371e-09 5.903247e-09 1.463379e-04 1.838257e-08 8.408794e-01 4.541057e-08 -5.458547e+00 3.763758e+03 2.899876e+02 4.000063e+02 -8.800786e+04 4.000063e+02 1.215424e+04
Iteration Continuity X-momentum Y-momentum Z-momentum Energy Tke Sdr Intermittency Heat Transfer 1 (W) Pinlet (Pa) T_outlet (K) twallFroide (K) surf_avg_q_crit (/s^2) Maximum tempfroide (K) Surface Average Helicity (/s)
11 3.111921e-10 6.967732e-09 1.939856e-09 1.489035e-09 3.637339e-05 1.190901e-08 1.233295e-03 1.514342e-08 -3.424275e-01 -2.047953e+02 2.900011e+02 3.904010e+02 -5.810358e+05 3.905252e+02 1.336589e+04
Conjugate-Gradient solver did not converge !
12 2.750237e-10 6.604475e-09 1.869473e-09 1.402315e-09 2.681946e-05 1.108801e-08 5.955147e-04 2.128098e-08 -5.063177e-01 3.204832e+01 2.899994e+02 3.851287e+02 -6.980901e+05 3.853471e+02 1.349346e+04
1486 1.772877e-10 1.146380e-08 5.247957e-09 2.874375e-09 2.170361e-04 2.508185e-09 6.915671e-05 1.255282e-08 4.900716e+00 1.318869e+02 2.957356e+02 3.059026e+02 -2.345214e+06 3.087469e+02 1.762329e+04
1487 1.794266e-10 1.145211e-08 5.258921e-09 2.874134e-09 1.135887e-04 2.508012e-09 6.529728e-05 1.261970e-08 4.907054e+00 1.317913e+02 2.957361e+02 3.059022e+02 -2.518939e+06 3.087460e+02 1.762613e+04
Temperature corrections limited on 7 cells in glue1
Temperature corrections limited on 1 cells in glue2
我复制了一些数据作为例子。我不希望在迭代1之前保存任何内容,中间的任何文本和我上次迭代后的任何文本。请建议
谢谢
Bineet
答案 0 :(得分:1)
您的预期输出并不是很清楚,但如果您只想提取以数字值开头的行(在可能的空格之后),grep
就可以了。
您的样本输入:
$ grep -P '^\s*\d+' sim
1 1.851301e-09 1.213569e-07 2.692437e-09 4.273490e-10 1.888124e-03 3.166891e-07 5.527057e-06 1.418467e-23 -9.974981e+00 2.505598e+03 2.900000e+02 4.000053e+02 -1.627486e+06 4.000053e+02 9.216386e+03
2 1.506520e-09 6.493389e-08 1.170308e-08 1.013586e-08 3.910613e-04 1.808261e-08 1.438014e+00 8.318085e-08 -9.193516e+00 3.435342e+03 2.899868e+02 4.000056e+02 -3.203329e+05 4.000056e+02 1.100795e+04
3 1.525969e-09 3.735938e-08 6.075371e-09 5.903247e-09 1.463379e-04 1.838257e-08 8.408794e-01 4.541057e-08 -5.458547e+00 3.763758e+03 2.899876e+02 4.000063e+02 -8.800786e+04 4.000063e+02 1.215424e+04
11 3.111921e-10 6.967732e-09 1.939856e-09 1.489035e-09 3.637339e-05 1.190901e-08 1.233295e-03 1.514342e-08 -3.424275e-01 -2.047953e+02 2.900011e+02 3.904010e+02 -5.810358e+05 3.905252e+02 1.336589e+04
12 2.750237e-10 6.604475e-09 1.869473e-09 1.402315e-09 2.681946e-05 1.108801e-08 5.955147e-04 2.128098e-08 -5.063177e-01 3.204832e+01 2.899994e+02 3.851287e+02 -6.980901e+05 3.853471e+02 1.349346e+04
1486 1.772877e-10 1.146380e-08 5.247957e-09 2.874375e-09 2.170361e-04 2.508185e-09 6.915671e-05 1.255282e-08 4.900716e+00 1.318869e+02 2.957356e+02 3.059026e+02 -2.345214e+06 3.087469e+02 1.762329e+04
1487 1.794266e-10 1.145211e-08 5.258921e-09 2.874134e-09 1.135887e-04 2.508012e-09 6.529728e-05 1.261970e-08 4.907054e+00 1.317913e+02 2.957361e+02 3.059022e+02 -2.518939e+06 3.087460e+02 1.762613e+04
(-P
激活PCRE模式,^
将匹配锚定到行开头,\s*
允许零个或多个空格字符可以在至少一个数字\d+
之前。)
答案 1 :(得分:1)
短 awk 方法:
awk '$1~/^[0-9]+/' file
输出:
1 1.851301e-09 1.213569e-07 2.692437e-09 4.273490e-10 1.888124e-03 3.166891e-07 5.527057e-06 1.418467e-23 -9.974981e+00 2.505598e+03 2.900000e+02 4.000053e+02 -1.627486e+06 4.000053e+02 9.216386e+03
2 1.506520e-09 6.493389e-08 1.170308e-08 1.013586e-08 3.910613e-04 1.808261e-08 1.438014e+00 8.318085e-08 -9.193516e+00 3.435342e+03 2.899868e+02 4.000056e+02 -3.203329e+05 4.000056e+02 1.100795e+04
3 1.525969e-09 3.735938e-08 6.075371e-09 5.903247e-09 1.463379e-04 1.838257e-08 8.408794e-01 4.541057e-08 -5.458547e+00 3.763758e+03 2.899876e+02 4.000063e+02 -8.800786e+04 4.000063e+02 1.215424e+04
11 3.111921e-10 6.967732e-09 1.939856e-09 1.489035e-09 3.637339e-05 1.190901e-08 1.233295e-03 1.514342e-08 -3.424275e-01 -2.047953e+02 2.900011e+02 3.904010e+02 -5.810358e+05 3.905252e+02 1.336589e+04
12 2.750237e-10 6.604475e-09 1.869473e-09 1.402315e-09 2.681946e-05 1.108801e-08 5.955147e-04 2.128098e-08 -5.063177e-01 3.204832e+01 2.899994e+02 3.851287e+02 -6.980901e+05 3.853471e+02 1.349346e+04
1486 1.772877e-10 1.146380e-08 5.247957e-09 2.874375e-09 2.170361e-04 2.508185e-09 6.915671e-05 1.255282e-08 4.900716e+00 1.318869e+02 2.957356e+02 3.059026e+02 -2.345214e+06 3.087469e+02 1.762329e+04
1487 1.794266e-10 1.145211e-08 5.258921e-09 2.874134e-09 1.135887e-04 2.508012e-09 6.529728e-05 1.261970e-08 4.907054e+00 1.317913e+02 2.957361e+02 3.059022e+02 -2.518939e+06 3.087460e+02 1.762613e+04