我有一个数据文件,比如file1.txt,我想匹配一个模式(“最佳匹配点:”或“最佳匹配点”),然后打印该行的最后一列。
best-fit point: 0.0000 0.0000 0.0000 x coordinate 0.0000
best-fit point: -0.4330 -0.2500 0.0884 x coordinate 0.5078
best-fit point: 0.8660 0.5000 -0.1768 x coordinate 2.0310
best-fit point: -0.4330 0.2500 0.1768 x coordinate 3.4003
best-fit point: 0.8660 1.0000 -0.0884 x coordinate 4.9236
best-fit point: 0.4330 0.7500 0.0000 x coordinate 5.4313
best-fit point: 0.8660 -0.5000 -0.3536 x coordinate 6.8006
best-fit point: 0.0000 0.0000 0.2652 x coordinate 7.9766
best-fit point: 1.2990 0.7500 0.0000 x coordinate 9.4998
best-fit point: 0.8660 0.5000 0.0884 x coordinate 10.0076
best-fit point: 1.2990 -0.7500 -0.2652 x coordinate 11.3769
best-fit point: 0.8660 -1.0000 -0.1768 x coordinate 11.8846
best-fit point: 0.0000 0.0000 -0.5303 x coordinate 13.2539 0.0000
0.5078
2.0310
3.4003
4.9236
5.4313
6.8006
7.9766
9.4998
10.0076
11.3769
11.8846
13.2539awk '/best-fit point:/{i==0 ; i++; print "K"i"="$8}' file-1.txt
如果任何列中没有负面数据,则此awk命令将成功工作。是否有其他方法打印模式匹配后的最后一列?
提前感谢!
发布于 2021-01-19 16:04:34
使用grep:
grep 'best-fit' file.txt | grep -Eo ' .[^ ]*只选择“最佳匹配”行,然后将其简化为"空格string线端“。如果您的格式与您的输入一样固定,您也可以只减少一个字符范围。grep 'best-fit' file.txt | cut -c60-只选择“最佳匹配”行,然后将其简化为"空格string线端“。
如果您的格式与您的输入一样固定,您也可以只减少一个字符范围。
A4
https://unix.stackexchange.com/questions/629890
复制相似问题