开发者

How to sort the files based on the grep count?

开发者 https://www.devze.com 2023-03-03 03:44 出处:网络
my grep -c command for a particular pattern 开发者_StackOverflow社区returns files as follows A:2 B:6

my grep -c command for a particular pattern 开发者_StackOverflow社区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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号