gpt4 book ai didi

linux - 查找文件中的最大数字

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:46:54 28 4
gpt4 key购买 nike

我正在尝试从文件中找到字符串中的最大数字。例如,在文件 password.txt 中我们有:

 jaime:45:/home/jaime:/bin/bash
sofia:113:/home/sofia:/bin/bash
marta:2015:/home/marta:/bin/bash
pedro:2024:/home/pedro:/bin/bash

所以最大的数字应该是 2024 我们必须将它保存到一个变量中:-

number=2024

我已经用 grepawksed 甚至 sort 尝试了几种方法,但没有任何解决方案。

最佳答案

我建议:

number=$(cut -d: -f 2 file | sort -n | tail -n 1)

关于linux - 查找文件中的最大数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41548766/

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