shell中将字符中换行符'\n'替换为空格

如下所示,文件hello.txt中有5行数据,要将这5行数据在一行中显示出来,并用空格分隔。

jie$ cat hello.txt 
1
2
3
4
5

从下方法均可实现: 
方法1.

jie$ echo `cat hello.txt` 
1 2 3 4 5

方法2.

jie$ cat hello.txt |sed ':jix;N;s/\n/ /g;b jix'
1 2 3 4 5

方法3.

jie$ cat hello.txt | xargs
1 2 3 4 5

猜你喜欢

转载自blog.csdn.net/kwame211/article/details/80313119