Why does wc increase character count by 1 ?
Matt Smith
matt.xtaz at gmail.com
Sat Sep 9 18:15:01 UTC 2017
On Sep 09 18:10, Manish Jain wrote:
>Hi,
>
>echo "abc 123" | wc -c
>
>I would expect wc to output 7, but actually I get 8.
>
>Indeed, I see similar behaviour with 'echo | wc -c'
>This should produce 0, but I get 1
>
>What might be the problem ? Thanks for any tips.
>Manish Jain
It's counting the \n linefeed. Try these:
echo "abc 123" | od -c
echo -n "abc 123" | od -c
echo -n "abc 123" | wc -c
--
Matt
More information about the freebsd-questions
mailing list