Split a line into 5 fields each into multiple lines

Friday, December 28, 2012 0 Comments


How can I replace every 5th comma in some input with a newline?

For example:

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15

becomes

1,2,3,4,5
6,7,8,9,10
11,12,13,14,15

awk -F, '{for(i=1;i<=NF;i++){printf("%s%s",$i,i%5?",":"\n")}}' file3

0 comments: