my grep -c command for a particular pattern returns files as follows
A:2
B:6
c:1
d:9
Now i want to sort the files based on this command. so my final op will be
c:1
A:2
B:6
d:9
how to use grep and sort together?
grep -c <pattern> * | sort -n -k2 -t:
The -k2
changes the key field, the -t:
sets the field separator to :
(the -n
means a numeric sort)
I would do it like this:
grep -c $pattern A B c d | sort -n -t: -k2
-n
means numeric sort, -t:
means that the column delimiter is :
and -k2
means that the second column is considered for sorting.
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