Bash:从每行提取多个条目

问题描述 投票:0回答:1

我有一个日志文件,在

grep my_function $LOG_FILE
之后看起来有点像这样:

[0] my_function took 96.78581194020808 ms
[1] my_function took 82.0779490750283 ms
[2] my_function took 187.79653799720109 ms
[1] my_function took 98.69955899193883 ms
[0] my_function took 10.296131949871778 ms[1] my_function took 2.5152561720460653 ms
[1] my_function took 2.210912061855197 ms
[2] my_function took 3.418975044041872 ms

从这个文件中,我只想提取每行中的数字。通常,我会使用

awk '{print $4}'
来执行此操作,但此日志包含几行和两个条目。但是,在这里,我有时需要从一行中选择两个单独的条目。我如何使用
bash
/GNU 工具正确选择这些?

awk gnu unix-text-processing
1个回答
0
投票

使用您显示的示例,请尝试以下

awk
解决方案。

awk -F'[. ]' '/my_function/{print $4}' Input_file

awk '/my_function/{print int($4)}' Input_file
© www.soinside.com 2019 - 2024. All rights reserved.