How to? Sort on hex value

samintz

Scott Mintz
May 20, 2008
1,555
26
Solon, OH, USA
Is there a way to sort a file, starting at a specific column, where that column is a hexadecimal value?

I have a symbol file that is out of order and very hard to find anything. I want to sort the file so the symbols are listed in increasing numeric order. I am currently using the SORT program that's built in to Windows, however it does a character sort and not a numeric sort so the value of 0xfc would come after 0xfb001234 which is not what i want.

the lines look something like this:
Code:
[Index]  Value       Size     Type      Bind    Other   Shndx   Name
 
[1]      0x0         0        4         0       0       0xfff1  dataSegPad.c
[2]      0xf5004000  0        3         0       0       0x1     
[3]      0x0         0        3         0       0       0x9     
[4]      0x0         0        1         0       0       0x9     __local_cie
[5]      0x0         0        3         0       0       0xa     
[6]      0x0         0        3         0       0       0xb     
[7]      0x0         0        3         0       0       0xc     
[8]      0x0         0        4         0       0       0xfff1  romfs_image_prj.s
[9]      0xf5004000  0        3         0       0       0x1     
[10]     0xf5218d06  0        3         0       0       0x1     
[11]     0x0         0        4         0       0       0xfff1  ../../BSP/ARM_926/sysALib.s
[12]     0xf5004000  0        3         0       0       0x1     
[13]     0xf5004000  0        2         0       0       0x1     $a
As you can see the natural sort order is by Index. I want it by Value. And the tool I'm using won't produce a listing in Value order.

I'm using SORT /+9 to sort on the value column. Can TPIPE do this kind of sort?
 
Aug 2, 2011
258
4
Berlin, Germany
For such tasks I often use the MS tool 'logparser'
Code:
>logparser -i:tsv -iseparator:spaces -rtp:-1 "select * from hex.dat order by value"
Filename                                  RowNumber [Index] Value      Size Type Bind Other Shndx  Name
----------------------------------------- --------- ------- ---------- ---- ---- ---- ----- ------ ---------------------------
C:\Program Files\JPSoft\TCMD14x64\hex.dat 13        [11]    0x0        0    4    0    0    0xfff1 ../../BSP/ARM_926/sysALib.s
C:\Program Files\JPSoft\TCMD14x64\hex.dat 10        [8]    0x0        0    4    0    0    0xfff1 romfs_image_prj.s
C:\Program Files\JPSoft\TCMD14x64\hex.dat 3        [1]    0x0        0    4    0    0    0xfff1 dataSegPad.c
C:\Program Files\JPSoft\TCMD14x64\hex.dat 8        [6]    0x0        0    3    0    0    0xb    <NULL>
C:\Program Files\JPSoft\TCMD14x64\hex.dat 9        [7]    0x0        0    3    0    0    0xc    <NULL>
C:\Program Files\JPSoft\TCMD14x64\hex.dat 6        [4]    0x0        0    1    0    0    0x9    __local_cie
C:\Program Files\JPSoft\TCMD14x64\hex.dat 5        [3]    0x0        0    3    0    0    0x9    <NULL>
C:\Program Files\JPSoft\TCMD14x64\hex.dat 7        [5]    0x0        0    3    0    0    0xa    <NULL>
C:\Program Files\JPSoft\TCMD14x64\hex.dat 15        [13]    0xf5004000 0    2    0    0    0x1    $a
C:\Program Files\JPSoft\TCMD14x64\hex.dat 4        [2]    0xf5004000 0    3    0    0    0x1    <NULL>
C:\Program Files\JPSoft\TCMD14x64\hex.dat 14        [12]    0xf5004000 0    3    0    0    0x1    <NULL>
C:\Program Files\JPSoft\TCMD14x64\hex.dat 11        [9]    0xf5004000 0    3    0    0    0x1    <NULL>
C:\Program Files\JPSoft\TCMD14x64\hex.dat 12        [10]    0xf5218d06 0    3    0    0    0x1    <NULL>
 
Statistics:
-----------
Elements processed: 13
Elements output:    13
Execution time:    0.01 seconds
 
>logparser -i:tsv -iseparator:spaces -stats:off -rtp:-1 "select [[Index]], Value, Size, Type, Bind, Other, Shndx,  Name from hex.dat order by value"
[Index] Value      Size Type Bind Other Shndx  Name
------- ---------- ---- ---- ---- ----- ------ ---------------------------
[11]    0x0        0    4    0    0    0xfff1 ../../BSP/ARM_926/sysALib.s
[8]    0x0        0    4    0    0    0xfff1 romfs_image_prj.s
[1]    0x0        0    4    0    0    0xfff1 dataSegPad.c
[6]    0x0        0    3    0    0    0xb    <NULL>
[7]    0x0        0    3    0    0    0xc    <NULL>
[4]    0x0        0    1    0    0    0x9    __local_cie
[3]    0x0        0    3    0    0    0x9    <NULL>
[5]    0x0        0    3    0    0    0xa    <NULL>
[13]    0xf5004000 0    2    0    0    0x1    $a
[2]    0xf5004000 0    3    0    0    0x1    <NULL>
[12]    0xf5004000 0    3    0    0    0x1    <NULL>
[9]    0xf5004000 0    3    0    0    0x1    <NULL>
[10]    0xf5218d06 0    3    0    0    0x1    <NULL>

I don't know why the columns look so messy here.
On my console window they are formatted well.
 

samintz

Scott Mintz
May 20, 2008
1,555
26
Solon, OH, USA
I found a switch combination on the tool that creates the listing that formats the values with leading zeroes. So a text sort actually sorts it correctly now. I don't have LOGPARSER on my machine Frank.
 
May 20, 2008
3,515
4
Elkridge, MD, USA
I found a switch combination on the tool that creates the listing that formats the values with leading zeroes. So a text sort actually sorts it correctly now. I don't have LOGPARSER on my machine Frank.
Great! Your alternative would have been to reprocess the file linie-by-line, replacing the 2nd word thus:
0x%@right[8,00000000%@left[-2,%@word[1,%line]]] - achieving the same format.
 

Similar threads