My data is a large text file that consists of 12 rows repeating. It looks something like this:
{
1
2
3
4
5
6
7
8
9
10
}
repeating over and over. I want to turn every 12 rows into columns. so the data would look like this:
{ 1 2 3 4 5 6 7 8 9 10 }
{ 1 2 3 4 5 6 7 8 9 10 }
{ 1 2 3 4 5 6 7 8 9 10 }
I have found some examples of how to convert all the rows to columns using awk: awk '{printf("%s ", $0)}'
, but no examples of how to convert every 12 rows into columns and then repeat the process.
You could use something like this:
NR%12
evaluates to true except when the record number is exactly divisible by 0. When it is true, the output field separator is used (which defaults to a space). When it is false, the record separator is used (by default, a newline).Testing it out:
Here is an idiomatic way (read golfed down version of Tom Fenech's answer) of doing it with
awk
:ORS
stands for Output Record Separator. We set theORS
toFS
which by default is space for every line except the 12th line where we set it toRS
which is a newline by default.