Results 1 to 2 of 2
  1. #1
    Join Date
    May 2010
    Posts
    1

    Unanswered: 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.

  2. #2
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •