comm shell command

1.awk command

1.1 Purpose 1: want to distinct and then count and sort by num

       1.1.1 Command: cat result.txt|awk '{print $1}'|uniq -c|sort -k 1n

Sort parameters:

     -k: sort by key (in this case column, pairs with -t)

  -n: sort as a number

  -r: reverse order

  (optional) -t: in case you want to change the key separator (default: space)

Uniq parameter:

  -w: choose the first N characters

Explanation:

  In your problem, we need to first sort the first column and then the second one. So there is a -k 1,1 followed by -k 2,2. But, the second key (ONLY) must be sorted as a number and in the reverse order. Thus, it should be -k 2nr,2.

Note that if the -n or -r sort parameters are outside -k parameter, they are applied to the whole input instead of specific keys.

Lastly, me must find the unique lines, but matching only the first 4 chars. Thus, uniq -w 4

 

猜你喜欢

转载自www.cnblogs.com/tben/p/11282346.html
今日推荐