Compaiting two files

From: Robert Binkley (rbinkl_at_comcast.net)
Date: 12/23/03

  • Next message: Raul Sossa S.: "SUMMARY: Out of Memory Message in Huge amount of Files"
    Date: Tue, 23 Dec 2003 11:03:23 -0600
    To: Tru64-Unix-Managers <tru64-unix-managers@ornl.gov>, Aix-L <aix-l@Princeton.EDU>
    
    

     
    This can be easily done with a simple Perl script...
    - - - - - - - - - - snip - - - - - - - - - -
    #!/bin/perl
    open(FD,"<file1") or die "could not open file1: $!\n";
    while ( <FD> ) {
    chomp;
    $in_file1{$_} = 1;
    }
    close(FD);

    open(FD,"<file2") or die "could not open file2: $!\n";
    while ( <FD> ) {
    chomp;
    next if ( $in_file1{$_} );
    print "$_\n";
    }
    close(FD);
    - - - - - - - - - - snip - - - - - - - - - -
    Now, if file1 looks like this:
    >cat file1
    Item1
    Item2
    Item3
    Item4
    and file2 looks like this:
    >cat file2
    Item5
    Item4
    Item2b
    Item1
    Item6
    then the output of the above Perl script will look like this:
    >perl perlscript
    Item5
    Item2b
    Item6
    Is that what you're looking for?
    Note that this could be easily modified to accept file names on the command
    line. The output could also be sorted if so desired.


  • Next message: Raul Sossa S.: "SUMMARY: Out of Memory Message in Huge amount of Files"

    Relevant Pages

    • Re: Delete file if it contains x y or z
      ... chomp @filelist; ... chomp $iline; ... I didn't really want to get into supplying a list of filenames to the script. ... I had a load of scripts that I had written when I first had a go at learning PERL a couple of years ago, but due to a system crash, I lost almos all of them, and find myself back at square one, only this time I am trying to achieve my goals without asking tons of Q's. ...
      (perl.beginners)
    • Re: array within array
      ... I'm new with Perl and need help with this simple script. ... Here's what I want to do; I have to flat files (pipe delimited, ... use chomp instead of chop ...
      (perl.beginners)
    • Re: array within array
      ... I'm new with Perl and need help with this simple script. ... below is incomplete and I'm doing an array within an array which is ...
      (perl.beginners)
    • Compaiting two files
      ... This can be easily done with a simple Perl script... ... if file1 looks like this: ...
      (AIX-L)
    • Re: Command line vs. cron
      ... I don't know if this is a Perl or UNIX problem and I'm hoping you can help me figure that out. ... When I run the script from the command line, the script prints to a log file the number of each of those processes that are running at the time of the script execution. ... chomp $tty; ... chomp $date; ...
      (perl.beginners)