我有一个非空文件(即使是大文件,400Ko),可以使用less
命令阅读。
但如果我尝试使用wc -l /path/to/file
命令输出行数,则会输出0
。
这可能怎么可能呢?
wc -l
报告0行。
First, count the characters in your file:
wc -c /path/to/file
You should get a non-zero value.
Now, filter out everything that isn't a newline:
tr -dc '\n' /path/to/file | wc -c
You should get back 0.
Or, delete the newlines and count the result.
tr -d '\n' | wc -c
You should get back the same value as in step 1.
wc命令会统计文件中'\n'字符的数量。你的文件中可能没有这个字符吗?
以下是GNU源代码: https://www.gnu.org/software/cflow/manual/html_node/Source-of-wc-command.html
查找COUNT(c)宏。
dd if=/dev/zero bs=1024 count=400 of=/tmp/nulls ; ls -log /tmp/nulls
输出结果显示该文件已存在:
400+0 records in
400+0 records out
409600 bytes (410 kB, 400 KiB) copied, 0.00343425 s, 119 MB/s
-rw-rw-r-- 1 409600 Feb 28 11:12 /tmp/nulls
wc -l /tmp/nulls
0 /tmp/nulls
hexdump -C /tmp/nulls | less
。 关于“html”:sensible-browser /tmp/nulls
显然表明了它的内容。 当然,你是正确的,它可能是Dos换行符,但这个答案展示了最简单的400K实例。 - agcfile
命令。file filename.html
filename.html: HTML document text, UTF-8 Unicode text, with very long lines, with no line terminators
wc
无法检测到。首先要进行转换。 - Kentwc
计算换行符的数量 - 可能是一行。 - Mark Setchell-l
选项的wc
的输出是什么?wc -L
的输出是什么? - Leonfile yourFile
- Kent