我想从以下行中提取 timeTaken 值:
<some other log data> Exception, Curl1-Time: 0.258315s. Curl2-Time: 3.9092588424683s Exiting.
我在 grep
和 awk
中使用以下命令:
grep -Po "Exception, Curl1-Time: \K(\d+.\d*)s. Curl2-Time: (\d+.\d+)" app.log | awk '{print $1 + $3}'
输出:4.167565
- 能否以更智能的方式完成此操作,也许使用 sed 或任何其他方式 bash 工具。
- 可以忽略尾随的“s”吗?在时间上 加法结果的值是正确的。
最佳答案
您已经在使用 PCRE。为什么不使用 Perl 本身?
perl -lne 'print $1 + $2
if /Exception, Curl1-Time: ([\d.]+)s\. Curl2-Time: ([\d.]+)/
' < input
关于linux - 从一行中提取多个 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34851350/