tsrrhhh tsrrhhh - 1 year ago 50
Bash Question

What is the three spaces after ' uniq -c ' command in shell

When using shell (bash) in os x, I execute

uniq -c
, then output is added three spaces to each line. What is this spaces? How can I eliminate that?


Common uniq implementations add padding spaces on the left to align the counts number. This both looks neater and allows for correct sorting by count even with a "brutal" lexicographical sort; notice however that this courtesy doesn't seem to be mandated by POSIX.

You can easily trim them adding sed in pipe:

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