The following awk script read the input file and creates an two dimensional array.
[tt]
awk '
NR==1 {
rows = $1;
cols = $2;
next;
}
{
if (++row_index > rows) exit;
for (col_index=1; col_index<=cols; col_index++)
array2[row_index, col_index] = substr($0,col_index,1);
}
END {
for (row_index=1; row_index<=rows; row_index++) {
Out = "Rows " row_index ": ";
for (col_index =1; col_index<=cols; col_index++) {
Out = Out array2[row_index,col_index] ", ";
}
print substr(Out, 1, length(Out)-2);
}
}
' input_file
[/tt]
With your datas, the result is :
[tt]
Rows 1: a, b, c, d
Rows 2: e, f, g, h
Rows 3: i, j, k, l
[/tt]
Jean Pierre.