Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

You input is actually demited by spaces not TAB. By default cut expects TAB. This should work:

cut -d ' ' -f1,2,5,6

It specifies the delimiter as ' ' (space).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top