如下所示,文件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
如下所示,文件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