3

Is there an option in uniq -c (or an alternative) that doesn't add additional whitespaces around the count number? Currently I generally pipe it through sed, like so:

sort | uniq -c | sed 's/^ *\([0-9]*\) /\1 /'

But this seems kinda redundant, particularly given how frequently I have to do this.

JohnnyTooBad
  • 77
  • 2
  • 6

1 Answers1

6

You can try to make the sed command as short as possible with

sort | uniq -c | sed 's/^ *//'

If you have GNU grep, you can also use the -P flag:

sort | uniq -c | grep -Po '\d.*'

(Do not use awk '{$1=$1};1', it will trim more than you want)

When you need this often, you can make a function or script calling

sort | uniq -c | sed 's/^ *//'

or only

uniq -c | sed 's/^ *//'
Walter A
  • 19,067
  • 2
  • 23
  • 43