Tuesday, June 26, 2018

QuickTip: Split Single Column into Multiple Columns

Consider a single column file which begins with

$ cat file.txt
1
yes
single
125K
no
2
no
married
100K
no
...

Suppose you want to split it into 5 columns so that it looks like

1 yes single 125K no
2 no married 100K no
...

You can use either,

$ xargs -n5 < file.txt

or if you want some control over the delimiter

$ paste - - - - - -d, < file.txt

1,yes,single,125K,no
2,no,married,100K,no


No comments: