我有一个文本文件,我想删除所有不以 5,4 或 3 个空格和整数值开头的行(包括空行)。
到目前为止,我已经手动删除了文本文件的第一部分,然后我在行中确定了一些我也想删除的单词并使用了 grep:
grep -v "iter" out_modif.log > out_modif2.log
grep -v "Stabilizing" out_modif2.log > out_modif3.log
grep . out_modif3.log > out_modif4.log
等等。
我试过了
grep -v "^[!0-9]" out.log > out2.log
但没有用(我猜是因为整数前面的空格)
输入文本文件的一部分示例:
Initialize using the hybrid initialization method.
Checking case topology...
-This case has both inlets & outlets
-Pressure information is available at the boundaries
iter scalar-0 scalar-1
1 1.000000e+00 0.000000e+00
2 8.345726e-04 0.000000e+00
iter continuity x-velocity y-velocity z-velocity
1 1.0000e+00 1.6601e-02 7.6482e-03 1.7253e-02
我希望命令的输出是一个只有以下内容的文件:
1 1.0000e+00 1.6601e-02 7.6482e-03 1.7253e-02
(包含整数的其他行使用制表符而不是空格)
我用你的输入调用了我的文件carles
:
grep -P '^ {3,5}[0-9]+[[:space:]]' carles
1 1.0000e+00 1.6601e-02 7.6482e-03 1.7253e-02
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句