python - linebreak after a certain number of columns -


i want columns written out in single line after printing out given number of columns in 1 line. original files in form of

a1 b1 c1 d1 e1 a2 b2 c2 d2 e2 a3 b3 c3 d3 e3 ... 

if choose 3, output should following:

a1 b1 c1 d1 e1 a2 b2 c2 d2 e2 a3 b3 c3 ... 

or if choose 2:

a1 b1  c1 d1 e1 a2 b2  c2 d2 e2 a3 b3  c3 ... 

i thankful solution; awk, sed or bash preferred. open python...

using gnu sed:

$ cat file a1 b1 c1 d1 e1 a2 b2 c2 d2 e2 a3 b3 c3 d3 e3 

$sed 's/ /\n/3g' file a1 b1 c1 d1 e1 a2 b2 c2 d2 e2 a3 b3 c3 d3 e3 

$ gsed 's/ /\n/2g' file a1 b1 c1 d1 e1 a2 b2 c2 d2 e2 a3 b3 c3 d3 e3 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -