wc -m in unix adds one character

▼魔方 西西 提交于 2019-12-20 04:06:13

问题


Counting a line with 4 characters with no new line character:

ACTG

wc -m gives me 5. With echo, I can fix this problem so

echo -n 'ACTG' | wc -m

But if ACTG is in a text file with no new line character, I get 5. Why is that so?

$ ls -l file

-rw-rw-r-- 1 user user 5 Feb 11 15:27 file
$ hexdump -C file

00000000  41 42 43 44 0a                                    |ABCD.|
00000005

回答1:


As hexdump has shown you, whatever editor you are using is adding a '\n' or 0x0A (new line) character at the end of the line when you save the file, even if you aren't writing one explicitly.

See: http://www.asciitable.com/



来源:https://stackoverflow.com/questions/35341207/wc-m-in-unix-adds-one-character

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!