gpt4 book ai didi

linux - 如何删除不以空格和整数开头的行

转载 作者:太空宇宙 更新时间:2023-11-04 09:59:52 26 4
gpt4 key购买 nike

我有一个文本文件,我想删除所有不是以 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

关于linux - 如何删除不以空格和整数开头的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57140440/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com