Help us understand the problem. What is going on with this article?

linuxでファイルを複数行を一行にする方法

More than 5 years have passed since last update.

1, trコマンドを利用する

~ koukou.chou.ts$ cat  test
1
2
3
4
5
6
7
8
9
10
~ koukou.chou.ts$ cat test | tr "\n" " ";echo
1 2 3 4 5 6 7 8 9 10 

2, awkコマンドを利用する

~ koukou.chou.ts$ awk '{if(NR%10){ORS=" "}else{ORS="\n"};print;}' test
1 2 3 4 5 6 7 8 9 10

3, perlスクリプトを利用

~ koukou.chou.ts$ perl -pe 's/\n/ /;' test && echo
1 2 3 4 5 6 7 8 9 10 

4, xargを利用

~ koukou.chou.ts$ cat test | xargs
1 2 3 4 5 6 7 8 9 10

5, vim のsedを利用

~ koukou.chou.ts$ vim test 
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
~                                                                                                                                                    
~                                                                                                                                                    
~                                                                                                                                                    
                                                                                                                                                  :%s/\n/ /g

6, sedを利用する

~ koukou.chou.ts$ sed 'N;N;N;N;N;N;N;N;N;s/\n/ /g' test
1 2 3 4 5 6 7 8 9 10
~ koukou.chou.ts$ 
zhangxianghong
1 tcp/ip network 2 operator 3 ruby beginner
http://rexceed.co.jp
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away