Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 9 Sep 2017 19:14:56 +0100
From:      Matt Smith <matt.xtaz@gmail.com>
To:        Manish Jain <bourne.identity@hotmail.com>
Cc:        "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org>
Subject:   Re: Why does wc increase character count by 1 ?
Message-ID:  <20170909181455.GB82102@gmail.com>
In-Reply-To: <VI1PR02MB12007715EC3BFAF626325B4EF66A0@VI1PR02MB1200.eurprd02.prod.outlook.com>
References:  <VI1PR02MB12007715EC3BFAF626325B4EF66A0@VI1PR02MB1200.eurprd02.prod.outlook.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170909181455.GB82102>