gpt4 book ai didi

linux - Grep 并增加值

转载 作者:太空宇宙 更新时间:2023-11-04 05:19:11 25 4
gpt4 key购买 nike

我想知道如何仅 grep 文件中的 Atoms.Timestep 并增加 Timestep 的值?例如添加 200。

我尝试使用 bash 文件,但它不起作用。

Atoms. Timestep: 0
1 76.494 75.0579 73.6777
2 75.5756 74.3821 74.9533
3 75.4282 72.7064 74.7586
4 74.6055 72.4862 73.3068
5 75.4501 73.045 71.9846
6 75.6282 74.7559 72.2756

最佳答案

试试这个:

cat your_file | grep -Eo "[0-9]+\.[0-9]+|[0-9]*" | sort | awk '{print $1+200}'

输出:

200
201
202
203
204
205
206
271.985
272.276
272.486
272.706
273.045
273.307
273.678
274.382
274.606
274.756
274.759
274.953
275.058
275.428
275.45
275.576
275.628
276.494

但这会四舍五入到 3 位数。

下面的行将保留 4 位小数。

cat your_file | grep -Eo "[0-9]+\.[0-9]+|[0-9]*" | sort | awk '{printf "%.4f\n", $1+200}'

输出:

200.0000
200.0000
201.0000
202.0000
203.0000
204.0000
205.0000
206.0000
271.9846
272.2756
272.4862
272.7064
273.0450
273.3068
273.6777
274.3821
274.6055
274.7559
274.7586
274.9533
275.0579
275.4282
275.4501
275.5756
275.6282
276.4940

关于linux - Grep 并增加值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44300461/

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