Solved

Files ,working with numers in Hex-Dec

Posted on 2006-06-25
3
182 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
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 150 total points
Comment Utility
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
Comment Utility
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
Comment Utility
ozo's suggestion reads STDIN
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now