Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

awk split column into multiple columns in staggered manner

Tags:

sed

awk

I have a text file containing a single column of data as below :

1
2
3
4
5
6

I want to split this into multiple columns using awk or sed command as follows:

1 2 3
4 5 6

How can I do this? Thanks in advance

like image 318
Nishant Bhaskar Avatar asked Nov 21 '25 09:11

Nishant Bhaskar


2 Answers

here is another approach

paste -d' ' - - - < file

with awk

awk 'ORS=NR%3?FS:RS' file

also

pr -3ats' ' file
like image 104
karakfa Avatar answered Nov 24 '25 23:11

karakfa


This should work because echo is a default command for xargs

xargs -n 3 file
like image 36
slitvinov Avatar answered Nov 24 '25 22:11

slitvinov