Solved

Files ,working with numers in Hex-Dec

Posted on 2006-06-25
3
183 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

912 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

17 Experts available now in Live!

Get 1:1 Help Now