If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > Compare part of two files in Perl

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-07-10, 14:04
niranjanlives niranjanlives is offline
Registered User
 
Join Date: May 2010
Posts: 1
Compare part of two files in Perl

Hi,
I'm a newbie in perl scripting. I want to compare first 18 characters of two files using perl and write output if they matches.

FileA;

Code:
835100000000000020000000001000000.000000000.000
835100000000000120000000001000000.000000000.000
835100000000000230000000001000000.000000000.000
835100000000000300000000001000000.000000000.000
835100000000000320000000001000000.000000000.000
835100000000000380000000001000000.000000000.000
835100000000000550000000001000000.000000000.000
835100000000000570000000001000012.000000001.000
FileB:
Code:
83510000000000002020100504000002.659000002.109000002.405000002.322
83510000000000012020100504000003.838000001.563000003.157000003.183
83510000000000019020100504000012.318000006.568000013.284000012.532
83510000000000020020100504000017.733000011.877000016.389000015.547
83510000000000023020100504000016.682000007.235000016.806000016.305
83510000000000030020100504000007.200000003.739000005.465000005.673
83510000000000032020100504000007.808000004.831000007.109000007.305
83510000000000038020100504000003.857000002.357000004.302000004.302
83510000000000050800000000000000.000000000.000000000.000000000.000
83510000000000051800000000000000.000000000.000000000.000000000.000
83510000000000055020100504000002.033000002.049000001.242000001.212
83510000000000057020100504000011.232000004.801000008.807000008.978
If the first 18 characters matches, output file B.

OutputFileB:
Code:
83510000000000002020100504000002.659000002.109000002.405000002.322
83510000000000012020100504000003.838000001.563000003.157000003.183
83510000000000023020100504000016.682000007.235000016.806000016.305
83510000000000030020100504000007.200000003.739000005.465000005.673
83510000000000032020100504000007.808000004.831000007.109000007.305
83510000000000038020100504000003.857000002.357000004.302000004.302
83510000000000055020100504000002.033000002.049000001.242000001.212
83510000000000057020100504000011.232000004.801000008.807000008.978
Any help would be much appreciated.
Reply With Quote
  #2 (permalink)  
Old 05-12-10, 09:08
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Baghdad, Iraq
Posts: 697
You need to write your problem statement more clearly.

From the way you've written it, it's just "if the first 18 characters of file A matches the first 18 characters of file B, write out file B." That doesn't seem very useful though.

Are you matching line by line? Can one line match any other line in the file, or does line 5 in A have to match line 5 in B?

And show what you've written so far, even if it's just an English description of an algorithm.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On