how to use cut here?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > how to use cut here?




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    how to use cut here?  
jeniffer


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-19-06 05: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






[ Post a follow-up to this message ]



    Re: how to use cut here?  
jeniffer


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-19-06 05: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






[ Post a follow-up to this message ]



    Re: how to use cut here?  
ld kelley (larry)


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-19-06 05: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





[ Post a follow-up to this message ]



    Re: how to use cut here?  
jeniffer


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-19-06 05: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...






[ Post a follow-up to this message ]



    Re: how to use cut here?  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-19-06 05: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





[ Post a follow-up to this message ]



    Re: how to use cut here?  
jeniffer


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-19-06 05: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






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:51 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register