wc -l 在非空文件上返回 0
wc -l returning 0 on a non-empty file
我在我的服务器上使用 Curl 从 https://api.data.gov/ed/collegescorecard/v1/schools?api_key=[my_API_key]
下载了一个 JSON 文件
(I have uploaded the file to TinyUpload if you want to play around with it.)
下载的文件为 1.5MB,并且有一个非常大(且有效)的 JSON 对象。但是,在服务器上,当我对文件 运行 命令 wc -l
时,它 returns 0. 运行 wc -c
returns 是正确的字节数。
我在 TextEdit 中打开文件,它看起来不错。我注意到我的服务器 (CentOS 5.5) 上的 man wc
和 Mac (Yosemite) 上的 man wc
似乎对 -l
标志的描述不同做:
CentOS 5.5:
print the newline counts
OSX 10.10.5 Yosemite
The number of lines in each input file is written to the standard output.
哪个手册是正确的? wc -l
算行数还是换行数?如果它确实计算行数而不是新行数,那么即使文件中有一行,wc -l
也可以 return 0 吗?
Mark 关于 this related SO post 上基于 Windows 的字符的评论是否也可能是正确的诊断?我 运行 cat -vet
针对我的文件,但无法使用 grep 找到 ^M
,而且手动搜索的文本太多了。
OS X 上的联机帮助页还说(描述中的第一段):
A line is defined as a string of characters delimited by a < newline> character.
所以两个版本的manpages之间没有矛盾。
由于您的文件没有换行符,wc -l
正确 returns 0.
我在我的服务器上使用 Curl 从 https://api.data.gov/ed/collegescorecard/v1/schools?api_key=[my_API_key]
下载了一个 JSON 文件(I have uploaded the file to TinyUpload if you want to play around with it.)
下载的文件为 1.5MB,并且有一个非常大(且有效)的 JSON 对象。但是,在服务器上,当我对文件 运行 命令 wc -l
时,它 returns 0. 运行 wc -c
returns 是正确的字节数。
我在 TextEdit 中打开文件,它看起来不错。我注意到我的服务器 (CentOS 5.5) 上的 man wc
和 Mac (Yosemite) 上的 man wc
似乎对 -l
标志的描述不同做:
CentOS 5.5:
print the newline counts
OSX 10.10.5 Yosemite
The number of lines in each input file is written to the standard output.
哪个手册是正确的? wc -l
算行数还是换行数?如果它确实计算行数而不是新行数,那么即使文件中有一行,wc -l
也可以 return 0 吗?
Mark 关于 this related SO post 上基于 Windows 的字符的评论是否也可能是正确的诊断?我 运行 cat -vet
针对我的文件,但无法使用 grep 找到 ^M
,而且手动搜索的文本太多了。
OS X 上的联机帮助页还说(描述中的第一段):
A line is defined as a string of characters delimited by a < newline> character.
所以两个版本的manpages之间没有矛盾。
由于您的文件没有换行符,wc -l
正确 returns 0.