I working on some code optimization and I would to inspect the size of my functions instead to read huge disassembly file. After compilation on Debug, I use the nm command to read the .o. We got this:
nm --size-sort $OBJFILEPATH.o
000000000000000b r __PRETTY_FUNCTION__.6473
0000000000000017 t extract_h
0000000000000036 t L_mult
000000000000003a t sature32
0000000000000042 t L_mac
0000000000000048 t L_add
000000000000005c t Mac16x11
0000000000000077 t L_shl
0000000000000083 t L_shr
00000000000000df T G729Convolve
0000000000000114 T G729Residu
00000000000001bc T G729Syn_filt_L_H
00000000000001bc T G729Syn_filt_L_SUBFR
Now, into a bash script I would like to parse only the 1st column where each line represent a single array element in bash.
My command will be:
read FUNCSIZE <<< $(nm --size-sort $OBJFILEPATH.o | awk '{print $1}')
And for make sure that everything is ok I check the size of my FUNCSIZE array.
SIZE=${#FUNCSIZE[@]}
echo size is $SIZE
for s in $FUNCSIZE
do
echo $s
done
I got this as output:
size is 1
000000000000000b
0000000000000017
0000000000000036
000000000000003a
0000000000000042
0000000000000048
000000000000005c
0000000000000077
0000000000000083
00000000000000df
0000000000000114
00000000000001bc
00000000000001bc
Why size is '1' and why I'm able to print each element like it was inside an array. It's seem that the output still have a 'space' ' ' at the end of the line. Is there any RegEx with awk that will avoid to include the separator field into the array?
Thank for your help!
EDIT AFTER ANSWER
read -a FUNCSIZE <<< $(nm --size-sort $OBJFILEPATH.o | awk '{print $1}')
SIZE=${#FUNCSIZE[*]}
for((i=0; i<SIZE; i++))
do
echo ${FUNCSIZE[$i]}
done
It sounds from your comment like this might be what you're really looking for:
$ cat tst.awk
{
size = strtonum("0x"$1)
sub(/^([^[:space:]]+[[:space:]]+){2}/,"")
name = $0
}
NR==FNR { oldSize[name] = size; next }
{
newSize[name] = size
if ( name in oldSize ) {
if ( oldSize[name] < newSize[name] ) {
bigger[name]
}
else if ( oldSize[name] > newSize[name] ) {
smaller[name]
}
}
else {
added[name]
}
}
END {
print "Got bigger:"
for (name in bigger) print "\t" name, oldSize[name], "->", newSize[name]
print "Got smaller:"
for (name in smaller) print "\t" name, oldSize[name], "->", newSize[name]
print "Added:"
for (name in added) print "\t" name
print "Deleted:"
for (name in oldSize) if ( !(name in newSize) ) print "\t" name
}
.
$ gawk -f tst.awk <(cat file1) <(cat file2)
Got bigger:
Mac16x11 92 -> 93
Got smaller:
L_mac 66 -> 65
Added:
extract_h
Deleted:
G729Residu
The above uses GNU awk for strtonum() and was run on these 2 input files:
$ cat file1
000000000000000b r __PRETTY_FUNCTION__.6473
0000000000000036 t L_mult
000000000000003a t sature32
0000000000000042 t L_mac
0000000000000048 t L_add
000000000000005c t Mac16x11
0000000000000077 t L_shl
0000000000000083 t L_shr
00000000000000df T G729Convolve
0000000000000114 T G729Residu
00000000000001bc T G729Syn_filt_L_H
00000000000001bc T G729Syn_filt_L_SUBFR
$ cat file2
000000000000000b r __PRETTY_FUNCTION__.6473
0000000000000017 t extract_h
0000000000000036 t L_mult
000000000000003a t sature32
0000000000000041 t L_mac
0000000000000048 t L_add
000000000000005d t Mac16x11
0000000000000077 t L_shl
0000000000000083 t L_shr
00000000000000df T G729Convolve
00000000000001bc T G729Syn_filt_L_H
00000000000001bc T G729Syn_filt_L_SUBFR
Just replace each cat file
with the corresponding nm ...
.