| Author |
how to use cut here?
|
|
| jeniffer 2006-03-19, 12:02 pm |
| Hi
I m somwwhat new to unix and i cannot figure out how do i extract the
values under the heading VALUE (see below) for all the files ...i used
cut command as cut -f3 -d ' ' but couldnt get the desired output.
i need the output to be the list of all unique values ( we'll use uniq
command i think) not including .rodata or .data (grep -v i think ) ...i
need to execute this all from a PERL script ...it has to be done for
all object files ...i wrote
$var = ".rodata\|.data";
system("objdump -r *.o|cut -f3 -d ' ' |grep -v $var");
i know that we'll have to remove statements like :
test1.o: file format elf32-i386
RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
from the output so that cut works coz it otherwise considers FOR as
the third field.
---------------------------------------------
[shell prompt]$ objdump -r *.o
test1.o: file format elf32-i386
RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
0000000a R_386_32 .rodata
0000000f R_386_PC32 printf
00000022 R_386_32 .rodata
00000027 R_386_PC32 printf
00000041 R_386_PC32 G
00000046 R_386_PC32 F
0000004e R_386_32 .rodata
00000053 R_386_PC32 printf
test.o: file format elf32-i386
RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
0000000a R_386_32 .rodata
0000000f R_386_PC32 printf
00000022 R_386_32 .rodata
00000027 R_386_PC32 printf
0000003a R_386_32 .rodata
0000003f R_386_PC32 printf
00000059 R_386_PC32 F1
0000005e R_386_PC32 F2
| |
| jeniffer 2006-03-19, 12:02 pm |
| i figured out a way :
[shell promp]$ objdump -r *.o | grep -v "RELOCATION\|OFFSET\|file
format"
| grep -v ".rodata\|.data"
0000000f R_386_PC32 printf
00000027 R_386_PC32 printf
00000041 R_386_PC32 G
00000046 R_386_PC32 F
00000053 R_386_PC32 printf
0000000f R_386_PC32 printf
00000027 R_386_PC32 printf
0000003f R_386_PC32 printf
00000059 R_386_PC32 F1
0000005e R_386_PC32 F2
now two problems remain :
a) using cut command n uniq command to extract unique third field
values
b)incorporating this command in a PERL system command
| |
| ld kelley (larry) 2006-03-19, 12:02 pm |
| jeniffer wrote:
> Hi
> I m somwwhat new to unix and i cannot figure out how do i extract the
> values under the heading VALUE (see below) for all the files ...i used
> cut command as cut -f3 -d ' ' but couldnt get the desired output.
> i need the output to be the list of all unique values ( we'll use uniq
> command i think) not including .rodata or .data (grep -v i think ) ...i
> need to execute this all from a PERL script ...it has to be done for
> all object files ...i wrote
>
> $var = ".rodata\|.data";
> system("objdump -r *.o|cut -f3 -d ' ' |grep -v $var");
> i know that we'll have to remove statements like :
> test1.o: file format elf32-i386
>
> RELOCATION RECORDS FOR [.text]:
> OFFSET TYPE VALUE
> from the output so that cut works coz it otherwise considers FOR as
> the third field.
>
> ---------------------------------------------
> [shell prompt]$ objdump -r *.o
>
> test1.o: file format elf32-i386
>
> RELOCATION RECORDS FOR [.text]:
> OFFSET TYPE VALUE
> 0000000a R_386_32 .rodata
> 0000000f R_386_PC32 printf
> 00000022 R_386_32 .rodata
> 00000027 R_386_PC32 printf
> 00000041 R_386_PC32 G
> 00000046 R_386_PC32 F
> 0000004e R_386_32 .rodata
> 00000053 R_386_PC32 printf
>
>
>
> test.o: file format elf32-i386
>
> RELOCATION RECORDS FOR [.text]:
> OFFSET TYPE VALUE
> 0000000a R_386_32 .rodata
> 0000000f R_386_PC32 printf
> 00000022 R_386_32 .rodata
> 00000027 R_386_PC32 printf
> 0000003a R_386_32 .rodata
> 0000003f R_386_PC32 printf
> 00000059 R_386_PC32 F1
> 0000005e R_386_PC32 F2
>
You might try using tr to compress the spaces out
.... | tr -s " " | cut -f3 -d " " | sort | uniq
--larry
| |
| jeniffer 2006-03-19, 12:02 pm |
| Thanks a lot !!! 
[shell prompt]$ objdump -r *.o | grep -v "RELOCATION\|OFFSET\|file
format"
| grep -v ".rodata\|.data"|tr -s " "|cut -f3 -d " "|sort|uniq
by this i m getting :
F
F1
F2
G
printf
now only 1 thing remains how to use this inside a PERL script...
| |
| Måns Rullgård 2006-03-19, 12:02 pm |
| "jeniffer" <zenith.of.perfection@gmail.com> writes:
> Thanks a lot !!! 
> [shell prompt]$ objdump -r *.o | grep -v "RELOCATION\|OFFSET\|file
> format"
> | grep -v ".rodata\|.data"|tr -s " "|cut -f3 -d " "|sort|uniq
>
> by this i m getting :
> F
> F1
> F2
> G
> printf
>
> now only 1 thing remains how to use this inside a PERL script...
Perl already has much more powerful tools built in:
my %values;
open OD, "objdump -r *.o |" or die;
while(<OD> ){
/^[[:xdigit:]]+\s+\w+\s+(\S+)$/ or next;
next if $1 =~ '\.rodata' or $1 =~ '\.data';
$values{$1} = 1;
}
close OD;
$, = $\ = "\n";
print sort keys %values;
--
Måns Rullgård
mru@inprovide.com
| |
| jeniffer 2006-03-19, 12:02 pm |
| i appreciate ur way but i wud have to do thru the system command only
in PERL coz that wud be easy n more understandable for me ...thnx a lot
|
|
|
|