wordcount (wc)
Hello, I have been using the 'wc' program (version 5.97) to manually verify some counts outputted by a component part of an application I am developing. I noticed that: echo 12345 | wc -m Gives me '6' as output. But I don't entirely understand why. On multi-line input 'wc' seems to add '1' to the character count in each sentence. One would say then that this '1' is caused by counting 'invisible' newline characters, but there is no newline in the example above. This off-by-one is probably intended behaviour (even though I am curious to find out why). I would expect something about this to be listed in the man page of 'wc', but could not find it there. With kind regards, Almer S. Tigelaar ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils
Re: wordcount (wc)
On Mon, Apr 21, 2008 at 9:27 AM, Almer S. Tigelaar [EMAIL PROTECTED] wrote: Hello, I have been using the 'wc' program (version 5.97) to manually verify some counts outputted by a component part of an application I am developing. I noticed that: echo 12345 | wc -m Gives me '6' as output. But I don't entirely understand why. On multi-line input 'wc' seems to add '1' to the character count in each sentence. One would say then that this '1' is caused by counting 'invisible' newline characters, but there is no newline in the example above. This off-by-one is probably intended behaviour (even though I am curious to find out why). I would expect something about this to be listed in the man page of 'wc', but could not find it there. Its counting the trailing newline. $ echo 12345 | wc -m 6 $ printf 12345\n | wc -m 6 $ printf 12345 | wc -m 5 $ echo -n 12345 | wc -m 5 Brock ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils
Re: wordcount (wc)
Hi, On Mon, Apr 21, 2008 at 04:27:35PM +0200, Almer S. Tigelaar wrote: I have been using the 'wc' program (version 5.97) to manually verify some counts outputted by a component part of an application I am developing. I noticed that: echo 12345 | wc -m Gives me '6' as output. But I don't entirely understand why. On multi-line input 'wc' seems to add '1' to the character count in each sentence. One would say then that this '1' is caused by counting 'invisible' newline characters, but there is no newline in the example above. There is a newline added by echo. Use echo -n to avoid this. Erik ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils