I am trying to create a script to reorder the contents of a text file. Below is the text file initially, followed by how I would like it reordered:
File initially:
---
Initial lines with text and/or numbers
Initial lines with text and/or numbers
Initial lines with text and/or numbers
Initial lines with text and/or numbers
Initial lines with text and/or numbers
x1 y1 z1 num1
1 E1,1
2 E1,2
3 E1,3
4 E1,4
5 E1,5
6 E1,6
...
{note to forum: there is always one linespace in between}
x2 y2 z2 num2
1 E2,1
2 E2,2
3 E2,3
4 E2,4
5 E2,5
6 E2,6
...
(The above sections are repeated hundreds of times.)
File reordered:
---
x y z 1 2 ...
x1 y1 z1 E1,1 E1,2 ...
x2 y2 z2 E2,1 E2,2 ...
...
I hope this makes sense. Essentially I need to be able to generate an Excel plot of x, y and z versus the energies. Other notes:
x1, y1, z1, E1,1 etc. are all numbers (decimals and floating point).
The '1', '2', '3', ... numbers above are exactly what appears.
Any help that can be provided would be great! I have attached a copy of the real initial file.
One further question. Attached is the Excel file I get when I import the resulting text file, delimiting it by space and comma. Notice the columns with all 1's, 2's, 3's, etc. Is there anyway to get rid of these columns? It's a real pain for plotting. Preferably, I would like these numbers to appear once above their respective energy columns as headings.
Can you help me? The commands you created were working great for the first file attached, until I encountered the second file attached, which doesn't work. The files should be the same, and I can't see a difference. But in the output from the awk command, the second file is not split into rows (two commas ,, appear where there should be a line break).
Attached files:
Original input file, for which awk command works perfectly
Original output file from awk command with input file from '1' above
New input file, for which awk doesn't work
New output file showing the rows not being divided
I need the command to work for both input file types, ideally. Your help would be greatly appreciated!!!