How to create a file with the following structure?

Consider the following rows:

E i -1 -1.0000000000000000e+00 -1.0000000000000000e+00 -1.0000000000000000e+00 0 0 1 0 0 0 0
U GEV MM
V -1 0 0 0 0 0 0 1 0
P 1 535 0.0000000000000000e+00 0.0000000000000000e+00 1.3330000000000000e+00 1.036606429653994e+01 1.02800000000000000e+01 0 0 0 0 0

where i ranges from 0 to 100000.

I would like to make the file composed of such rows, i.e.

E 1 -1 -1.0000000000000000e+00 -1.0000000000000000e+00 -1.0000000000000000e+00 0 0 1 0 0 0 0
U GEV MM
V -1 0 0 0 0 0 0 1 0
P 1 535 0.0000000000000000e+00 0.0000000000000000e+00 1.3330000000000000e+00 1.036606429653994e+01 1.02800000000000000e+01 0 0 0 0 0
E 1 -1 -1.0000000000000000e+00 -1.0000000000000000e+00 -1.0000000000000000e+00 0 0 1 0 0 0 0
U GEV MM
V -1 0 0 0 0 0 0 1 0
P 1 535 0.0000000000000000e+00 0.0000000000000000e+00 1.3330000000000000e+00 1.036606429653994e+01 1.02800000000000000e+01 0 0 0 0 0
E 2 -1 -1.0000000000000000e+00 -1.0000000000000000e+00 -1.0000000000000000e+00 0 0 1 0 0 0 0
    U GEV MM
    V -1 0 0 0 0 0 0 1 0
    P 1 535 0.0000000000000000e+00 0.0000000000000000e+00 1.3330000000000000e+00 1.036606429653994e+01 1.02800000000000000e+01 0 0 0 0 0
...

Could you please tell me how can I do this?

My approach starts from creating a script file in which I type,

touch file.txt
for i in {0.. 100000 }; 
do echo 'E i -1 -1.0000000000000000e+00 -1.0000000000000000e+00 -1.0000000000000000e+00 0 0 1 0 0 0 0' >> file.txt;
echo 'U GEV MM' >> file.txt
echo '-1 0 0 0 0 0 0 1 0' >> file.txt
echo 'P 1 535 0.0000000000000000e+00 0.0000000000000000e+00 1.3330000000000000e+00 1.036606429653994e+01 1.02800000000000000e+01 0 0 0 0 0' >> file.txt
done

But clearly there is something wrong, as i stays as i in the generated file, and the number of strings is much smaller than expected (4*100000).


You want to keep the number of occurrences inside the loop to a minimum (open and closing file.txt 100K x4 will really stress your system without any good reason).

#!/bin/bash

declare -a a
i=0
while ((i++ < 100000)); do
    a+=("E $i -1 -1.0000000000000000e+00 -1.0000000000000000e+00 -1.0000000000000000e+00 0 0 1 0 0 0 0" 'U GEV MM' '-1 0 0 0 0 0 0 1 0' 'P 1 535 0.0000000000000000e+00 0.0000000000000000e+00 1.3330000000000000e+00 1.036606429653994e+01 1.02800000000000000e+01 0 0 0 0 0')
done
printf '%s\n%s\n%s\n' "${a[@]}" > file.txt