Skip to main content
4 of 4
added 447 characters in body
Stéphane Chazelas
  • 586.6k
  • 96
  • 1.1k
  • 1.7k

For an arbitrary number of columns:

awk -v col=6 '{printf "%s%s", (NR>1) ? (NR-1) % col ? "," : RS : "", $0} END{if (NR) print ""}' < your-file 

With pr (assuming the input like in your sample doesn't contain one of the special sequences recognised by some pr implementations; with the GNU one (as found on CEntOS), that includes at least the form-feed character):

pr -t -a -s, -6 < your-file 

With GNU pr, you'll find you can't get more than 36 columns (half of 72, the default page width), unless you also use -w (or non-standard -W), but then you get some truncation / padding. You can work around that with -J (also a GNU extension), but who knows what other side effect that entails.

For 45 columns with GNU pr:

pr -Jtas, -w90 -45 

(YMMV with other pr implementations, I find the pr command to be quite a jolly mess).

Stéphane Chazelas
  • 586.6k
  • 96
  • 1.1k
  • 1.7k