如何使用 bash 和 awk 从这些数据中提取值?
我 grep 了这些,如何提取这些值?
... cavity_2mgl_wt_strip57001.out: Total cavity volume (A3) : ( 1.240E+01) cavity_2mgl_wt_strip58001.out: Total cavity volume (A3) : ( 2.408E+00) cavity_2mgl_wt_strip60001.out: Total cavity volume (A3) : ( 4.935E+00) cavity_2mgl_wt_strip61001.out: Total cavity volume (A3) : ( 1.319E+00) cavity_2mgl_wt_strip63001.out: Total cavity volume (A3) : ( 1.532E-01) cavity_2mgl_wt_strip64001.out: Total cavity volume (A3) : ( 1.137E+01) ...
我需要文件名中的索引#以粗体显示:
cavity_2mgl_wt_strip76001.out: Total cavity volume (A3) : ( 1.276E+01)
并且我需要括号中的数字:
cavity_2mgl_wt_strip76001.out: Total cavity volume (A3) : ( 1.276E+01)
I grepped these, how do I extract the values?
... cavity_2mgl_wt_strip57001.out: Total cavity volume (A3) : ( 1.240E+01) cavity_2mgl_wt_strip58001.out: Total cavity volume (A3) : ( 2.408E+00) cavity_2mgl_wt_strip60001.out: Total cavity volume (A3) : ( 4.935E+00) cavity_2mgl_wt_strip61001.out: Total cavity volume (A3) : ( 1.319E+00) cavity_2mgl_wt_strip63001.out: Total cavity volume (A3) : ( 1.532E-01) cavity_2mgl_wt_strip64001.out: Total cavity volume (A3) : ( 1.137E+01) ...
and I need the index # in the filename in bold:
cavity_2mgl_wt_strip76001.out: Total cavity volume (A3) : ( 1.276E+01)
and I need the number in the parenthesis:
cavity_2mgl_wt_strip76001.out: Total cavity volume (A3) : ( 1.276E+01)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
或者如果您的 grep 值已经在文件中
or if your grepped values are already in a file
当然,perl 中的长度比 awk 中短得多。我不知道你的格式有多灵活;我输入了一些通配符以防万一:
Sure is a lot shorter in perl than awk. I don't know how flexible your format is; I put in a few wildcards just in case:
使用 sed 怎么样?
第一个捕获是“条带”和下一个点之间的线部分。
然后跳过最后一个左括号之前的行。
第二个捕获是最后一对括号之间的数字(删除了所有前导和尾随空格)。
How about using sed?
The first capture is of the part of the line between "strip" and the next dot.
Then the line until the last opening bracket is skipped.
The second capture is of the number (with any leading and trailing space removed) between the last pair of brackets.
在纯 bash 中:
In pure bash: