Search code examples
macosbashwc

WC on OSX - Return includes spaces


When I run the word count command in OSX terminal like wc -c file.txt I get the below answer that includes spaces padded before the answer. Does anyone know why this happens, or how I can prevent it?

    18000 file.txt

I would expect to get:

18000 file.txt

This occurs using bash or bourne shell.


Solution

  • I suppose it is a way of getting outputs to line up nicely, and as far as I know there is no option to wc which fine tunes the output format.

    You could get rid of them pretty easily by piping through sed 's/^ *//', for example.

    There may be an even simpler solution, depending on why you want to get rid of them.