gpt4 book ai didi

linux - 如何更改 grep 查看文件/打印结果的顺序?

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

我有一个目录,里面有一堆文件名是数字的。它们没有前导零,所以如果我在该目录中执行类似 grep hello * 的操作,我可能会得到如下内容:

22:hello, world!
6:hello
62:"Say hello to them for me."

我希望结果是这样的:

6:hello
22:hello, world!
62:"Say hello to them for me."

我想到的第一个想法是用 grep hello * | 对结果进行数字排序sort -n 但是我失去了 grep 的颜色,我想保留它。最好的方法是什么?

最佳答案

ls * | sort -n | xargs -d '\n' grep hello

关于linux - 如何更改 grep 查看文件/打印结果的顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17100244/

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