Reputation: 151
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?
Upvotes: 6
Views: 5551
Reputation: 14147
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.
Upvotes: 3
Reputation: 8637
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)
Upvotes: 9