Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux unix中的wc-m添加了一个字符_Linux_Wc - Fatal编程技术网

Linux unix中的wc-m添加了一个字符

Linux unix中的wc-m添加了一个字符,linux,wc,Linux,Wc,计算包含4个字符且没有新行字符的行: ACTG wc-m给我5。使用echo,我可以解决此问题,以便 echo -n 'ACTG' | wc -m 但是如果ACTG在一个没有新行字符的文本文件中,我得到5。为什么会这样 $ ls -l file -rw-rw-r-- 1 user user 5 Feb 11 15:27 file $ hexdump -C file 00000000 41 42 43 44 0a |A

计算包含4个字符且没有新行字符的行:

ACTG
wc-m
给我5。使用echo,我可以解决此问题,以便

echo -n 'ACTG' | wc -m
但是如果
ACTG
在一个没有新行字符的文本文件中,我得到5。为什么会这样

$ 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(新行)字符,即使您没有显式地编写一个


请参见:

请参见答案的编辑。我认为我们无法在SE站点上标记重复项,但请参见: