How to get the differences between text files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • koduruabhinav
    New Member
    • Sep 2010
    • 8

    How to get the differences between text files

    i have two modules.txt files
    module1.txt
    module2. txt


    i have to comare the conents of files and i have to print the output as folls

    module1 module2
    .COMPENSATION ( "ZHOLD" ), .COMPENSATION ("EXTERNAL" ),

    .CLKIN1_PERIOD ( 5 ), .CLKIN1_PERIOD ( 5.000000 ),


    i want the differences to be printed like that
    but i was unable

    the code i have developed is

    Code:
    my @codes1 = split /\./, $modcode_from_1;(text in module1)
    my @codes2 = split /\./, $modcode_from_2;(text in module2)
    
    
    
    
    print "\t\t****************THE DIFFERENCES IN THE FILES ARE AS FOLLOWS****************\n\n\n";
    
    printf "\t\t\t%-45s %s\n\n\n", $filename1, $filename2;
    
    my $i = 0;
    foreach (@codes1) {
        unless ($codes1[$i] eq $codes2[$i]) {
            
            printf "\t%-45s is not the same as %s\n\n", $codes1[$i], $codes2[$i];
    
    
        
        }
        
        
        
        $i++;
    }
    Attached Files
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    What's the output of your code?
    For debugging purposes, please insert at line 20 following line:
    Code:
    printf ("i=%s, c1=%s, c2=%s\n", $i, $codes1[$i], $codes2[$i]);
    Then show the output here.

    Comment

    • koduruabhinav
      New Member
      • Sep 2010
      • 8

      #3
      The output is in the imagge i have uploaded.proble m is i have used dot as split parameter.so it is splittin 5.000
      as 5 and oooo and taking it as two words and comparing.
      and the result is not according .
      the above code

      module_from_1 contains module1.txt
      module_from_2 contains module 2.txt

      so i have to compare the both and print the differences as

      module1 module2
      parameter1 is not same as parameter2
      so please try to help me

      i=0, c1= , c2=
      i=1, c1=CLOCK_HOLD ( "FALSE" ), , c2=CLOCK_HOLD ( "FALSE" ),
      i=2, c1=CLKOUT4_CASC ADE ( "FALSE" ), , c2=CLKOUT4_CASC ADE ( "FALSE" ),
      i=3, c1=BANDWIDTH ( "OPTIMIZED" ), , c2=BANDWIDTH ( "OPTIMIZED" ),
      i=4, c1=CLKFBOUT_USE _FINE_PS ( "FALSE" ), , c2=CLKFBOUT_USE _FINE_PS ( "FALSE" ),
      i=5, c1=CLKOUT0_USE_ FINE_PS ( "FALSE" ), , c2=CLKOUT0_USE_ FINE_PS ( "FALSE" ),
      i=6, c1=CLKOUT1_USE_ FINE_PS ( "FALSE" ), , c2=CLKOUT1_USE_ FINE_PS ( "FALSE" ),
      i=7, c1=CLKOUT2_USE_ FINE_PS ( "FALSE" ), , c2=CLKOUT2_USE_ FINE_PS ( "FALSE" ),
      i=8, c1=CLKOUT3_USE_ FINE_PS ( "FALSE" ), , c2=CLKOUT3_USE_ FINE_PS ( "FALSE" ),
      i=9, c1=CLKOUT4_USE_ FINE_PS ( "FALSE" ), , c2=CLKOUT4_USE_ FINE_PS ( "FALSE" ),
      i=10, c1=CLKOUT5_USE_ FINE_PS ( "FALSE" ), , c2=CLKOUT5_USE_ FINE_PS ( "FALSE" ),
      i=11, c1=CLKOUT6_USE_ FINE_PS ( "FALSE" ), , c2=CLKOUT6_USE_ FINE_PS ( "FALSE" ),
      i=12, c1=COMPENSATION ( "ZHOLD" ), , c2=COMPENSATION ( "EXTERNAL" ),
      i=13, c1=STARTUP_WAIT ( "FALSE" ), , c2=STARTUP_WAIT ( "FALSE" ),
      i=14, c1=CLKFBOUT_MUL T_F ( 5, c2=CLKFBOUT_MUL T_F ( 5
      i=15, c1=000000 ), , c2=000000 ),
      i=16, c1=CLKFBOUT_PHA SE ( 0, c2=CLKFBOUT_PHA SE ( 0
      i=17, c1=000000 ), , c2=000000 ),
      i=18, c1=CLKOUT0_DIVI DE_F ( 10, c2=CLKOUT0_DIVI DE_F ( 10
      i=19, c1=000000 ), , c2=000000 ),
      i=20, c1=CLKOUT0_DUTY _CYCLE ( 0, c2=CLKOUT0_DUTY _CYCLE ( 0
      i=21, c1=500000 ), , c2=500000 ),
      i=22, c1=CLKOUT0_PHAS E ( 0, c2=CLKOUT0_PHAS E ( 0
      i=23, c1=000000 ), , c2=000000 ),
      i=24, c1=CLKOUT1_DUTY _CYCLE ( 0, c2=CLKOUT1_DUTY _CYCLE ( 0
      i=25, c1=500000 ), , c2=500000 ),
      i=26, c1=CLKOUT1_PHAS E ( 0, c2=CLKOUT1_PHAS E ( 0
      i=27, c1=000000 ), , c2=000000 ),
      i=28, c1=CLKOUT2_DUTY _CYCLE ( 0, c2=CLKOUT2_DUTY _CYCLE ( 0
      i=29, c1=500000 ), , c2=500000 ),
      i=30, c1=CLKOUT2_PHAS E ( 0, c2=CLKOUT2_PHAS E ( 0
      i=31, c1=000000 ), , c2=000000 ),
      i=32, c1=CLKOUT3_DUTY _CYCLE ( 0, c2=CLKOUT3_DUTY _CYCLE ( 0
      i=33, c1=500000 ), , c2=500000 ),
      i=34, c1=CLKOUT3_PHAS E ( 0, c2=CLKOUT3_PHAS E ( 0
      i=35, c1=000000 ), , c2=000000 ),
      i=36, c1=CLKOUT4_DUTY _CYCLE ( 0, c2=CLKOUT4_DUTY _CYCLE ( 0
      i=37, c1=500000 ), , c2=500000 ),
      i=38, c1=CLKOUT4_PHAS E ( 0, c2=CLKOUT4_PHAS E ( 0
      i=39, c1=000000 ), , c2=000000 ),
      i=40, c1=CLKOUT5_DUTY _CYCLE ( 0, c2=CLKOUT5_DUTY _CYCLE ( 0
      i=41, c1=500000 ), , c2=500000 ),
      i=42, c1=CLKOUT5_PHAS E ( 0, c2=CLKOUT5_PHAS E ( 0
      i=43, c1=000000 ), , c2=000000 ),
      i=44, c1=CLKOUT6_DUTY _CYCLE ( 0, c2=CLKOUT6_DUTY _CYCLE ( 0
      i=45, c1=500000 ), , c2=500000 ),
      i=46, c1=CLKOUT6_PHAS E ( 0, c2=CLKOUT6_PHAS E ( 0
      i=47, c1=000000 ), , c2=000000 ),
      i=48, c1=REF_JITTER1 ( 0, c2=REF_JITTER1 ( 0
      i=49, c1=010000 ), , c2=010000 ),
      i=50, c1=REF_JITTER2 ( 0, c2=REF_JITTER2 ( 0
      i=51, c1=010000 ), , c2=010000 ),
      i=52, c1=CLKOUT1_DIVI DE ( 20 ), , c2=CLKOUT1_DIVI DE ( 20 ),
      i=53, c1=CLKOUT2_DIVI DE ( 40 ), , c2=CLKOUT2_DIVI DE ( 40 ),
      i=54, c1=CLKOUT3_DIVI DE ( 60 ), , c2=CLKOUT3_DIVI DE ( 60 ),
      i=55, c1=CLKOUT4_DIVI DE ( 80 ), , c2=CLKOUT4_DIVI DE ( 80 ),
      i=56, c1=CLKOUT5_DIVI DE ( 100 ), , c2=CLKOUT5_DIVI DE ( 100 ),
      i=57, c1=CLKOUT6_DIVI DE ( 120 ), , c2=CLKOUT6_DIVI DE ( 120 ),
      i=58, c1=DIVCLK_DIVID E ( 1 ), , c2=DIVCLK_DIVID E ( 1 ),
      i=59, c1=CLKIN1_PERIO D ( 5 ), , c2=CLKIN1_PERIO D ( 5
      i=60, c1=CLKIN2_PERIO D ( 5 ), , c2=000000 ),
      i=61, c1=LOC ( "MMCM_ADV_X 0Y0" ), , c2=CLKIN2_PERIO D ( 5
      i=62, c1=VCOCLK_FREQ_ MAX ( 1200, c2=000000 ),
      i=63, c1=000000 ), , c2=LOC ( "MMCM_ADV_X 0Y5" ),
      i=64, c1=VCOCLK_FREQ_ MIN ( 600, c2=VCOCLK_FREQ_ MAX ( 1200
      i=65, c1=000000 ), , c2=000000 ),
      i=66, c1=CLKIN_FREQ_M AX ( 700, c2=VCOCLK_FREQ_ MIN ( 600
      i=67, c1=000000 ), , c2=000000 ),
      i=68, c1=CLKIN_FREQ_M IN ( 10, c2=CLKIN_FREQ_M AX ( 700
      i=69, c1=000000 ), , c2=000000 ),
      i=70, c1=CLKPFD_FREQ_ MAX ( 450, c2=CLKIN_FREQ_M IN ( 10
      i=71, c1=000000 ), , c2=000000 ),
      i=72, c1=CLKPFD_FREQ_ MIN ( 10, c2=CLKPFD_FREQ_ MAX ( 450
      i=73, c1=000000 )) i_MMCM_ADV ( , c2=000000 ),
      i=74, c1=CLKFBIN(CLKF BIN), , c2=CLKPFD_FREQ_ MIN ( 10
      i=75, c1=PSCLK(GND), , c2=000000 )) i_MMCM_ADV (
      i=76, c1=PWRDWN(\i_MM CM_ADV/PWRDWN_INT ), , c2=CLKFBIN(CLKF BIN),
      i=77, c1=DCLK(GND), , c2=PSCLK(GND),
      i=78, c1=DEN(GND), , c2=PWRDWN(\i_MM CM_ADV/PWRDWN_INT ),
      i=79, c1=CLKINSEL(\i_ MMCM_ADV/CLKINSEL_INT ), , c2=DCLK(GND),
      i=80, c1=CLKIN2(GND), , c2=DEN(GND),
      i=81, c1=RST(\i_MMCM_ ADV/RST_INT ), , c2=CLKINSEL(\i_ MMCM_ADV/CLKINSEL_INT ),
      i=82, c1=PSINCDEC(\i_ MMCM_ADV/PSINCDEC_INT ), , c2=CLKIN2(GND),
      i=83, c1=DWE(GND), , c2=RST(\i_MMCM_ ADV/RST_INT ),
      i=84, c1=PSEN(\i_MMCM _ADV/PSEN_INT ), , c2=PSINCDEC(\i_ MMCM_ADV/PSINCDEC_INT ),
      i=85, c1=CLKIN1(clk_I BUF_7819), , c2=DWE(GND),
      i=86, c1=CLKOUT3(CLKO UT3), , c2=PSEN(\i_MMCM _ADV/PSEN_INT ),
      i=87, c1=CLKOUT3B(\i_ MMCM_ADV/CLKOUT3B ), , c2=CLKIN1(clk_I BUF_2571),
      i=88, c1=CLKFBOUT(CLK FBOUT), , c2=CLKOUT3(CLKO UT3),
      i=89, c1=CLKFBSTOPPED (\i_MMCM_ADV/CLKFBSTOPPED ), , c2=CLKOUT3B(\i_ MMCM_ADV/CLKOUT3B ),
      i=90, c1=CLKFBOUTB(\i _MMCM_ADV/CLKFBOUTB ), , c2=CLKFBOUT(CLK FBOUT),
      i=91, c1=CLKOUT1(CLKO UT1), , c2=CLKFBSTOPPED (\i_MMCM_ADV/CLKFBSTOPPED ),
      i=92, c1=CLKOUT5(CLKO UT5), , c2=CLKFBOUTB(\i _MMCM_ADV/CLKFBOUTB ),
      i=93, c1=DRDY(\i_MMCM _ADV/DRDY ), , c2=CLKOUT1(CLKO UT1),
      i=94, c1=CLKOUT0(clk_ out0_OBUF_7848) , , c2=CLKOUT5(CLKO UT5),
      i=95, c1=CLKOUT4(CLKO UT4), , c2=DRDY(\i_MMCM _ADV/DRDY ),
      i=96, c1=CLKOUT1B(\i_ MMCM_ADV/CLKOUT1B ), , c2=CLKOUT0(clk_ out0_OBUF_2333) ,
      i=97, c1=CLKINSTOPPED (\i_MMCM_ADV/CLKINSTOPPED ), , c2=CLKOUT4(CLKO UT4),
      i=98, c1=CLKOUT0B(\i_ MMCM_ADV/CLKOUT0B ), , c2=CLKOUT1B(\i_ MMCM_ADV/CLKOUT1B ),
      i=99, c1=CLKOUT2(CLKO UT2), , c2=CLKINSTOPPED (\i_MMCM_ADV/CLKINSTOPPED ),
      i=100, c1=CLKOUT2B(\i_ MMCM_ADV/CLKOUT2B ), , c2=CLKOUT0B(\i_ MMCM_ADV/CLKOUT0B ),
      i=101, c1=PSDONE(\i_MM CM_ADV/PSDONE ), , c2=CLKOUT2(CLKO UT2),
      i=102, c1=CLKOUT6(CLKO UT6), , c2=CLKOUT2B(\i_ MMCM_ADV/CLKOUT2B ),
      i=103, c1=LOCKED(i_MMC M_ADV_ML_NEW_I1 ), , c2=PSDONE(\i_MM CM_ADV/PSDONE ),
      i=104, c1=DI({GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND}), , c2=CLKOUT6(CLKO UT6),
      i=105, c1=DADDR({GND, GND, GND, GND, GND, GND, GND}), , c2=LOCKED(LOCKE D_OBUF_2386),
      i=106, c1=DO({\i_MMCM_ ADV/DO15 , \i_MMCM_ADV/DO14 , \i_MMCM_ADV/DO13 , \i_MMCM_ADV/DO12 , \i_MMCM_ADV/DO11 , \i_MMCM_ADV/DO10 , \i_MMCM_ADV/DO9 , \i_MMCM_ADV/DO8 , \i_MMCM_ADV/DO7 , \i_MMCM_ADV/DO6 , \i_MMCM_ADV/DO5 , \i_MMCM_ADV/DO4 , \i_MMCM_ADV/DO3 , \i_MMCM_ADV/DO2 , \i_MMCM_ADV/DO1 , \i_MMCM_ADV/DO0 }) , c2=DI({GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND}),
      Attached Files

      Comment

      • chaarmann
        Recognized Expert Contributor
        • Nov 2007
        • 785

        #4
        For i=1 to 58 all runs fine, there are no differences.
        But it shows that at i=59 there is a difference. The problem is: why did the message inside the until()-condition, (see line 15) not print right before??? It must have been executed! Or have you modified it ? Or have you misspelled the variable name "codes1" and used a lowercase-el instead of a one character there? But then you should get a warning unless you have disabled it or also defined the misspelled variable before.

        For debugging purposes, please run your program with 2 files that have only 3 lines each and where 1 is different!!! Then show the output here again.
        Listing "millions" of lines here (and also without code tags) doesn't help much and only confuses.

        By the way, all other lines are "different" because your algorithm doesn't recognise inserted or deleted lines. If you want to make a real diff, you should also compare with the "surroundin g" of the current line to find an offset point.

        If you want to split by dot, but not inside a number, you must change your regular expression to use lookahead. So replace "\." with "\.(?!\d)". This means, split at a do only if the following character is not a number.

        Comment

        • koduruabhinav
          New Member
          • Sep 2010
          • 8

          #5
          ya fine tanq for ur suggestion.i have to start tomorrow the thing u have said

          Comment

          Working...