1/05/2016

linux join every 3 lines in a file

$ cat file.txt
xxxxxxxxx
yyyyyyyyyyy
zzz
aaaaaaaaa
bbbbbb
ccccc
$ perl -pi -e 's/\n/ / if $.%3' file.txt
$ cat file.txt
xxxxxxxxx yyyyyyyyyyy zzz
aaaaaaaaa bbbbbb ccccc

http://www.unix.com/shell-programming-and-scripting/115070-how-can-i-join-three-lines-into-one-unix.html

没有评论: