30
27

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2014-11-12

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$ 
30
27
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
27

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?