本文介绍了mac 的 WC 命令显示少一个结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个超过 60MB 的文本文件.它有 5105043 行的条目,但是当我执行 wc -l 时,它只给出 5105042 个结果,比实际结果少一个.有谁知道为什么会这样?

I have a text file which has over 60MB size. It has got entries in 5105043 lines, but when I am doing wc -l it is giving only 5105042 results which is one less than actual. Does anyone have any idea why it is happening?

文件大的时候是不是很常见?

Is it a common thing when the file size is large?

推荐答案

最后一行不包含新行.

获得您想要的结果的一个技巧是:

One trick to get the result you want would be:

sed -n '=' <yourfile> | wc -l

这告诉 sed 只是打印文件中每一行的行号,然后 wc 计数.可能有更好的解决方案,但这是有效的.

This tells sed just to print the line number of each line in your file which wc then counts. There are probably better solutions, but this works.

这篇关于mac 的 WC 命令显示少一个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 06:35