I have a directory with a bunch of files with numerical filenames. They don't have leading zeroes, so if I do something like grep hello *
in that directory I might get something like this:
22:hello, world!
6:hello
62:"Say hello to them for me."
I'd rather have the result be like this:
6:hello
22:hello, world!
62:"Say hello to them for me."
The first thought that occured to me was to sort the results numerically with grep hello * | sort -n
but then I lose grep's colors, which I'd like to keep. What's the best way to do that?
ls * | sort -n | xargs -d '\n' grep hello
Ah -- grep
suppresses its colors when its output is a pipe (which is probably a good thing). But this can be overridden by supplying --color=always
, which makes the | sort -n
approach work:
grep --color=always hello * | sort -n
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With