I have a file that looks like this:
# Time-averaged data for fix avetimeall
# TimeStep Number-of-rows
# Row c_gyrationchunkall
1000 3
1 2.09024e-14
2 4.88628
3 5.69321
2000 3
1 2.10518e-14
2 8.33702
3 8.83162
3000 3
1 1.96656e-14
2 12.1396
3 11.5835
...
In my file, the first three lines are always headers. After the headers, my file lists blocks of data of the same size, each starting with a labeling subheader. I want to reorganize the data in my file such that the data in each block are sent into a line starting with the relevant portion of the label of that block and listing the relevant data values of that block afterwards, all separated from each other by spaces. As an example, I want to convert the sample above into:
# Time-averaged data for fix avetimeall
# TimeStep c_gyrationchunkall
1000 2.09024e-14 4.88628 5.69321
2000 2.10518e-14 8.33702 8.83162
3000 1.96656e-14 12.1396 11.5835
...
How do I do this in Bash? I have some experience in Bash, but I'm afraid not enough to handle this problem swiftly...
bash
is a poor tool for multiline text processing. Perl (man perl
) would be a better choice. – waltinator Dec 03 '23 at 00:591000 3
, what is the significance of the3
? does this designate the number of follow-on lines? will all such lines always have a3
in the 2nd field or could it vary, and if it can vary, then please update the sample to show an example – markp-fuso Dec 03 '23 at 02:14