Unix中的wc -m添加一个字符 [英] wc -m in unix adds one character

查看:131
本文介绍了Unix中的wc -m添加一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

计数没有新行字符的4个字符的行:

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

ACTG

wc -m给了我5.通过回显,我可以解决此问题,

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

echo -n 'ACTG' | wc -m

但是如果ACTG在没有换行符的文本文件中,我得到5.为什么会这样?

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

推荐答案

正如hexdump向您展示的那样,无论您使用什么编辑器,当您在行末添加'\ n'或0x0A(新行)字符保存文件,即使您未明确编写文件也是如此.

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.

请参阅: http://www.asciitable.com/

这篇关于Unix中的wc -m添加一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆