gpt4 book ai didi

linux - Bash 输出最高值的行

转载 作者:IT王子 更新时间:2023-10-29 01:10:17 26 4
gpt4 key购买 nike

我的问题很像 this one但有一点不同;我想要输出在第三个选项卡上得分最高的行。我的数据是这样的:

1.gui  Qxx  16
2.gui Qxy 23
3.guT QWS 11

我想得到这个:

1.gui  Qxy  23
3.guT QWS 11

我用过:

cat file.f | uniq | cut -d" " -f3 | sort | uniq -d >>out.f

但没有得到我想要的!?

最佳答案

使用排序:

$ sort -rk3 file             # Sort on column 3, display all results

2.gui Qxy 23
1.gui Qxx 16
3.guT QWS 11

$ sort -rk3 file | head -2 # Sort on column 3, filter number of results

2.gui Qxy 23
1.gui Qxx 16

$ sort -rk3 file | uniq # Sort on column 3, on display unique results

2.gui Qxy 23
1.gui Qxx 16
3.guT QWS 11

-r 反向排序,最高优先。

-k3 在第 3 列排序。


如果您只想显示第 3 列大于某个值 (即 15) 的行,请尝试使用 awk:

awk '$3>15' file | sort -rk3  # Display line where column 3 > 15 and sort

2.gui  Qxy  23
1.gui  Qxx  16

关于linux - Bash 输出最高值的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13581225/

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