Solved

Files ,working with numers in Hex-Dec

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PERL get the value for query 4 157
Perl for loop for 2000 ms 7 109
pipe to sed or perl, please help 5 135
use google analytics code in perl script 2 90
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…

685 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