Padding lines in a file with newlines

Hi Guys,

I have a file as shown below:

55
6
77
8
88
98
7
85
45
544
1
33
32
13
13
23
44
11
67
87
243
56
344
23
133
1343
12
10
1155
321
15
899
654

The data is supposed to be arranged in a group of 10 values. Some groups do not have all 10 values.

So for example the following numbers belong to one group:

55
6
77
8
88
98
7
85
45
544

The following set of numbers belongs to another group but does not have all 10 values:

1
33
32
13

I would like to stuff this group with blank lines.

So my final output file should look like this:

55
6
77
8
88
98
7
85
45
544
1
33
32
13
 
 
 
 
 

13
23
44
11
67
87
 
 
 

243
56
344
23
133
1343
12
10
 
 
1155
321
15
899
654
 
 
 
 
 

So group 1 had all 10 values, group 2 (numbers 1,33,32,13) had only 4 values hence, padding of 6 more newlines to make it 10; group 3 (13,23,44,11,67,87) has only 6 values so padd it with 4 newlines to make it 10, etc.

Next I want to collect all these values in an array including the empty lines as a null array element.

How can I do this?

Thanks for your help.

How do you group numbers?

These numbers are extracted from another file which has groups of 10. All I want is to pad the file which has missing entries, with newlines. Will it be easier if I modify the original file as follows:

55
6
77
8
88
98
7
85
45
544

1
33
32
13

13
23
44
11
67
87

243
56
344
23
133
1343
12
10

1155
321
15
899
654





So now I have inserted a newline between individual groups.Group1 has all 10 entries, group 2 has only 4 entries (that means I will have to add 6 newlines), group 3 has 6 entries (so I will have to add 4 lines) and so on.

Hope this helps.

If your groups are paded with a newline as in your 2nd example, this works :

#!/bin/bash
while read L
do
	[ -n "$L" ] && { ((i++)); echo $L; continue; }
	until [ $i -eq 10 ]
	do	((i++)); echo
	done
	i=0
done < infile

Thanks, that worked.

Can you please explain the syntax? Appreciate your help.

while read L # reads on lie from input and ssign it to L
do
    [ -n "$L" ] && { ((i++)); echo $L; continue; }
        # if L is not empty then increment i, output L, next iteration of the loop
    until [ $i -eq 10 ] # doesn't need explanation
    do    ((i++)); echo 
    done
    i=0 # reset i for the next 10 count
done < infile

If you want to see what happens during the running of the script, you can

bash -x scriptname