I have some huge log files I need to sort. All entries have a 32 bit hex number which is the sort key I want to use.
some entries are one liners like
bla bla bla 0x97860afa bla bla
others are a bit more complex, start with the same type of line above and expand to a block of lines marked by curly brackets like the example below. In this case the entire block has to move to the position defined by the hex nbr. Block example-
bla bla bla 0x97860afc bla bla
bla bla {
blabla
bla bla {
bla
}
}
I can probably figure it out but maybe there is a simple perl or awk solution that will save me 1/2 day.
Transferring comments from OP:
Indentation can be space or tab, I can enhance that on any proposed solution, I think that Brian summarizes well: Specifically, do you want to sort “items” which are defined as a chunk of text that starts with a line containing a “0xNNNNNNNN”, and contains everything up to (but not including) the next line which contains a “0xNNNNNNNN” (where the N’s change, of course). No lines interspersed.
Something like this might work (Not tested):
The problem is that you said “huge” log files, so storing the file in memory will probably be inefficient. However, if you want to sort it, I suspect you’re going to need to do that.
If storing in memory is not an option, you can always just print the data to a file instead, with a format that will allow you to sort it by some other means.