Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

File comparison

myname182myname182 Member Posts: 9
Does anyone have a script or know how I would go about creating a script that compares to files and returns the line or line # where there is a discrepancy?

Thanks for the help.

Comments

  • JonathanJonathan Member Posts: 2,914
    Hi,

    If you're on a Linux/UNIX system, I think there is a program called diff which will do what you want. If you wanted to present the output in a certain way, you can capture diff's output to your Perl script and then do any parsing of it.

    Jonathan

    -------------------------------------------
    Count your downloads:
    http://www.downloadcounter.com/
    And host your site:
    http://www.incrahost.com/
    Don't say I never give you anything... ;-)

  • myname182myname182 Member Posts: 9
    Hi,

    I am on a linux system, but I need to do it all in perl. I also know of the 'fc' command in linux, but again, i cant use it. It needs to be all perl. Thanks for the suggestion though.

    Peter


    : If you're on a Linux/UNIX system, I think there is a program called diff which will do what you want. If you wanted to present the output in a certain way, you can capture diff's output to your Perl script and then do any parsing of it.
    :
    : Jonathan
    :
    : -------------------------------------------
    : Count your downloads:
    : http://www.downloadcounter.com/
    : And host your site:
    : http://www.incrahost.com/
    : Don't say I never give you anything... ;-)
    :
    :

  • JonathanJonathan Member Posts: 2,914
    Hi,

    : I am on a linux system, but I need to do it all in perl. I also
    : know of the 'fc' command in linux, but again, i cant use it. It
    : needs to be all perl. Thanks for the suggestion though.
    Ah, OK, I see. Writing a powerful differencing engine is not so easy, but a simple way to do it would be open both files and go through them line by line, comparing each line in them.

    You'll need to tidy this up, but this may work:-

    [code]
    #Read data from files.
    open FILEA, ";
    close FILEA;
    open FILEB, ";
    close FILEB;

    #Compare.
    for ($count=0; $count<@filea_data; $count++) {
    if ($filea_data[$count] ne $fileb_data[$count]) {
    print "Difference on line " . ($count + 1) . ".";
    }
    }

    [/code]

    Note that I haven't tested this, it may have error or something but it gives you the idea of what I'm thining anyway. :)

    Hope I've helped you some,

    Jonathan

    -------------------------------------------
    Count your downloads:
    http://www.downloadcounter.com/
    And host your site:
    http://www.incrahost.com/
    Don't say I never give you anything... ;-)

  • myname182myname182 Member Posts: 9
    [b][red]This message was edited by myname182 at 2002-10-16 8:53:16[/red][/b][hr]
    Sweet! thanks! I'll mess around with it.

    Peter

    : Hi,
    :
    : : I am on a linux system, but I need to do it all in perl. I also
    : : know of the 'fc' command in linux, but again, i cant use it. It
    : : needs to be all perl. Thanks for the suggestion though.
    : Ah, OK, I see. Writing a powerful differencing engine is not so easy, but a simple way to do it would be open both files and go through them line by line, comparing each line in them.
    :
    : You'll need to tidy this up, but this may work:-
    :
    : [code]
    : #Read data from files.
    : open FILEA, ";
    : close FILEA;
    : open FILEB, ";
    : close FILEB;
    :
    : #Compare.
    : for ($count=0; $count<@filea_data; $count++) {
    : if ($filea_data[$count] ne $fileb_data[$count]) {
    : print "Difference on line " . ($count + 1) . ".";
    : }
    : }
    :
    : [/code]
    :
    : Note that I haven't tested this, it may have error or something but it gives you the idea of what I'm thining anyway. :)
    :
    : Hope I've helped you some,
    :
    : Jonathan
    :
    : -------------------------------------------
    : Count your downloads:
    : http://www.downloadcounter.com/
    : And host your site:
    : http://www.incrahost.com/
    : Don't say I never give you anything... ;-)
    :
    :



  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    ________ / http://forcoder.org / free ebooks and video tutorials about < Python, Ruby, Delphi, Visual Basic .NET, C++, Assembly, PHP, Go, Scratch, R, Java, JavaScript, Visual Basic, Swift, PL/SQL, C#, MATLAB, Perl, C, Objective-C Alice, Fortran, Julia, Dart, Kotlin, Erlang, Scala, Scheme, Rust, D, Hack, COBOL, Lua, FoxPro, Logo, Prolog, SAS, Lisp, Clojure, ABAP, Apex, ML, Bash, Transact-SQL, Awk, LabVIEW, F#, VBScript, Crystal, Ada /> __________

Sign In or Register to comment.