Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Files ,working with numers in Hex-Dec

Posted on 2006-06-25
3
Medium Priority
?
189 Views
Last Modified: 2008-03-06
Hi ,plese help me to solve the problem:

I have a file with content

Adress1    Adress2      ColumnA      ColumnB
----------- ------------   -------------- -------------
010FAC3  2345ABC     Text1           Text2
010AAB3  1345ABC     Text3           Text4
010BA13  1234567      Text5           Text6
.
.
.

Adress1 and Adress2 are some memory adreseses in HEX

I need a script in perl that read this file and add to the file column (Adress2-Adress1)in decimal and if it's not difficult sorted by this new column

Output file should be :
Adress1    Adress2     NewColumn(Adress2-Adress1 in decimal) ColumnA      ColumnB
010BA13  1234567      17992532                                               Text5           Text6
010AAB3  1345ABC     19116041                                               Text3           Text4
010FAC3  2345ABC     35872761                                               Text1           Text2

Please can somebody help me in solving this problem

Thanks,
Inga

0
Comment
Question by:Inga_dusha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 600 total points
ID: 16980450
my @x;
while( <> ){
    next unless /^[0-9a-f]+\s+[0-9a-f]+/i;
    push @x,[split];
}
splice @$_,2,0,(hex $_->[1])-hex $_->[0] for @x;
$"="\t";
print "@$_\n" for sort{$a->[2]<=>$b->[2]} @x;
0
 

Author Comment

by:Inga_dusha
ID: 16981675
ozo,please can you explain me ,where I am reading the file here ?

It's should be something like this or what ?

open(file1, "<file.txt") || die("Could not open result file");
while( $record = <file1> ){
    next unless /^[0-9a-f]+\s+[0-9a-f]+/i;
    push @x,[split];
}

Thanks for help
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16982814
ozo's suggestion reads STDIN
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question