1 4 6 7 8 9 0 1 0
1 3 4 8 8 9 0 3 2
1 6 7 8 8 8 8 7 1
4 3 6 7 9 1 3 2 1
4 3 4 5 6 7 7 7 7
4 3 4 5 6 3 3 3 7
4 3 4 5 6 3 3 3 7
5 4 6 6 6 6 6 2 4
5 3 4 8 8 9 0 3 2
5 6 7 8 8 8 8 7 1
5 6 7 8 8 8 8 7 1
5 6 7 8 8 8 8 7 1
5 6 7 8 8 8 8 7 1
I need to read each line starting with the same number and put them into a nested array. In this simplified example I need to read all lines starting with 1 and put them into a nested array then later sort this array based on a column. Do the same for all lines starting with the same number. Basically I need to read each line starting with the same number put them in to nested array sort it and then print it, and continue doing th same for the remaining lines that start with the same number. The nested array:
1 4 6 7 8 9 0 1 0
1 3 4 8 8 9 0 3 2
1 6 7 8 8 8 8 7 1
Sorting it based on column 9:
1 4 6 7 8 9 0 1 0
1 6 7 8 8 8 8 7 1
1 3 4 8 8 9 0 3 2
The nested array:
5 4 6 6 6 6 6 2 4
5 3 4 8 8 9 0 3 2
5 6 7 8 8 8 8 7 1
5 6 7 8 8 8 8 7 1
5 6 7 8 8 8 8 7 1
5 6 7 8 8 8 8 7 1
After sorting:
5 6 7 8 8 8 8 7 1
5 6 7 8 8 8 8 7 1
5 6 7 8 8 8 8 7 1
5 6 7 8 8 8 8 7 1
5 4 6 6 6 6 6 2 4
5 3 4 8 8 9 0 3 2
I now How to put lines into a nested array and sort them based on column. My trouble is that I don't know how to read lines starting with the same number and put them into an array then continue doing the same for the rest of the file. Please help! Thanks.
In reply to How can I read multiple lines starting with the same number and put in to a nested array and print it to a file? by opolat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |