为什么 wc 命令比预期的多一个字符? [英] Why does the wc command count one more character than expected?
问题描述
以下是我的文件中存储的内容
The following is the content stored in my file
This is my Input
因此,使用 wc -c
命令我们可以获得文件中存储的字符数.
So, using wc -c
command we can get the number of characters stored in the file.
我在 Ubuntu 中使用 Vim 编辑的上述文件的预期输出是 16.但是,wc -c
命令返回 17
.
My expected output for above file that edited by using Vim in Ubuntu is 16. But, wc -c
command returns 17
.
为什么输出是这样的?行尾甚至没有回车.那么,第 17 个字符是什么?
Why is the output like this? There isn't even a carriage return at end of line. So, what is the 17th character?
推荐答案
当然你已经进入了.也许你看不到.考虑以下两个示例:
Of course you had enter. Maybe you can't see it. Consider these two examples:
echo -n "This is my Input" | wc -c
16
因为-n
是为了避免回车,但是
Because -n
is for avoiding enter, but
echo "This is my Input" | wc -c
17
看看这个例子,看看新的一行:
Look at this example too see the new line:
echo "This is my Input" | od -c
od
转储八进制和其他格式的文件.-c
选择 ASCII 字符或反斜杠转义.
od
dumps files in octal and other formats. -c
selects ASCII characters or backslash escapes.
这里是od
的文件和用法示例:
And here is an example for file and usage of od
:
这篇关于为什么 wc 命令比预期的多一个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!