So basically I want to print out certain columns of the .data
, .rodata
and .bss
sections of an ELF binary, and I use this command:
readelf -S hello | grep "data\|bss" | cut -f1,2,5,6
but to my surprise, the results are:
[15] .rodata PROGBITS 080484d8 0004d8 000020 00 A 0 0 8
[24] .data PROGBITS 0804a00c 00100c 000008 00 WA 0 0 4
[25] .bss NOBITS 0804a014 001014 000008 00 WA 0 0 4
which means the cut
didn't work...
I don't know why and after some search online, I still don't know how to make it right, could anyone give me some help?
I would have used awk
here since you can do all with one command.
readelf -S hello | awk '/data|bss/ {print $1,$2,$5,$6}'
awk
will work with any blank space a separator. One space, multiple space, tabs etc.