Need to remove the count from the output when using “uniq -c” command

后端 未结 5 811
有刺的猬
有刺的猬 2020-12-06 13:16

I am trying to read a file and sort it by number of occurrences of a particular field. Suppose i want to find out the most repeated date from a log file then i use uniq -c o

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 14:09

    If you want to work with the count field downstream, following command will reformat it to a 'pipe friendly' tab delimited format without the left padding:

     .. | sort | uniq -c | sed -r 's/^ +([0-9]+) /\1\t/'
    

    For the original task it is a bit of an overkill, but after reformatting, cut can be used to remove the field, as OP intended:

     .. | sort | uniq -c | sed -r 's/^ +([0-9]+) /\1\t/' | cut -d $'\t' -f2-
    

提交回复
热议问题