gpt4 book ai didi

unix - 为什么 "wc"命令说我的文件中只有一行,而实际上却只有两行?

转载 作者:行者123 更新时间:2023-12-04 03:49:30 24 4
gpt4 key购买 nike

请看以下示例:

$ cat < demo
man
car$
$
$ od -x < demo
0000000 616d 0a6e 6163 0072
0000007
$
$ wc < demo
1 2 7

如您所见,我在那里有3个字符( man:6d 61 6e),其后是换行符( \n:0a),然后还有另外三个( car:63 61 75)以NUL字符(00)结尾。显然,该文件中有两行,但是wc命令报告该文件只有一行。是什么赋予了?还是您认为为了在Unix中符合条件,必须以换行符终止? NUL不算在内吗?

最佳答案

Or do you think that in order to qualify as a line in Unix you must be terminated with a newline character?



实际上,是的-甚至 POSIX 都说:

The wc utility shall read one or more input files and, by default, write the number of newlines, words, and bytes contained in each input file to the standard output.

关于unix - 为什么 "wc"命令说我的文件中只有一行,而实际上却只有两行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39830504/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com