gpt4 book ai didi

linux - 在行字符串中找到最大数并显示两列 - linux

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

我想在文件中的字符串中找到最大数量

我已经有一个脚本来获取最大数量

counters_2016080822.log:2016-08-08 15:55:00,10.26.x.x,SERVER@10.26.x.x,SSCM_VRC/sscm-vrc-flow-20160602,,transactions.tps,13
counters_2016080823.log:2016-08-08 23:00:00,10.26.x.x,SERVER@10.26.x.x,SSCM_VRC/sscm-vrc-flow-20160602,,transactions.tps,14
counters_2016080823.log:2016-08-08 23:05:00,10.26.x.x,SERVER@10.26.x.1x,SSCM_VRC/sscm-vrc-flow-20160602,,transactions.tps,19

首先将最后一列数字放入新的 .txt 文件使用 sed

sed 's/^.*tps,//'

13

14

19

然后排序并得到第一行

grep -Eo '[0-9]+' myfile.txt | sort -rn | head -n 1

19

但现在我想找到最大值然后得到最大值,现在是时候了(日期和时间或只是时间)

如下:

23:05:00 19

最佳答案

也许是这样

echo "counters_2016080822.log:2016-08-08 15:55:00,10.26.x.x,SERVER@10.26.x.x,SSCM_VRC/sscm-vrc-flow-20160602,,transactions.tps,13
counters_2016080823.log:2016-08-08 23:00:00,10.26.x.x,SERVER@10.26.x.x,SSCM_VRC/sscm-vrc-flow-20160602,,transactions.tps,14
counters_2016080823.log:2016-08-08 23:05:00,10.26.x.x,SERVER@10.26.x.1x,SSCM_VRC/sscm-vrc-flow-20160602,,transactions.tps,19" | \
sed -r 's/^.*:([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}),.*,([0-9]+)$/\1 \2/' | \
sort -n -k 3 -t ' ' | tail -n 1

关于linux - 在行字符串中找到最大数并显示两列 - linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38868344/

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