去除行尾符$

有时候需要去除文件的行尾符$

1、单行时

当只有单行时,我们可以简单的echo -n 解决

[root@Master1 ~]# 
[root@Master1 ~]# echo a > single.txt //生成带行尾符号$的一个文件
[root@Master1 ~]# cat -A single.txt
a$
[root@Master1 ~]# echo -n `cat single.txt` > single.txt
[root@Master1 ~]# cat -A single.txt
a[root@Master1 ~]#

2、多行时

[root@Master1 ~]#  cut -d: -f1 < /etc/passwd | head -n3
root
bin
daemon
[root@Master1 ~]# cut -d: -f1 < /etc/passwd | head -n3 |xargs echo -n
root bin daemon[root@Master1 ~]#
[root@Master1 ~]# cut -d: -f1 < /etc/passwd | head -n3 |xargs echo -n |sed 's/[[:space:]]//g'
rootbindaemon[root@Master1 ~]#
[root@Master1 ~]#