in reply to Re: use to files - grep one to eliminate entries from another file.
in thread use to files - grep one to eliminate entries from another file.

I'm looking to find common lines between two files
$ man comm NAME comm - compare two sorted files line by line SYNOPSIS comm [OPTION]... FILE1 FILE2 DESCRIPTION Compare sorted files FILE1 and FILE2 line by line. With no options, produce three-column output. Column one +contains lines unique to FILE1, column two contains lines unique to FIL +E2, and column three contains lines common to both files. -1 suppress lines unique to FILE1 -2 suppress lines unique to FILE2 -3 suppress lines that appear in both files --help display this help and exit --version output version information and exit
  • Comment on Re^2: use to files - grep one to eliminate entries from another file.
  • Download Code

Replies are listed 'Best First'.
Re^3: use to files - grep one to eliminate entries from another file.
by newkendall (Initiate) on Jan 23, 2012 at 19:18 UTC

    Trying to do all of this in Perl - management doesn't want UNIX commands so I can port this to Windows machines. Thanks.

      Thanks - probably won't work for management; I'll just try to figure it out in Perl on my own. Thanks for your efforts

        At least, look at the manual page, and deduce how comm is implemented. It works on sorted files. Big hint! So, using this big blinking hint, how would I implement this?
        1. Sort both files.
        2. Open both files.
        3. If one of the files is empty, the lines in the other file are unique to said file. Then you're done.
        4. Read a line from both files.
        5. If lines are equal, they appear in both files. Goto 4.
        6. If the line from the first file is less then (string wise) the line from the second, it's unique to the first file. If the first file doesn't have more lines, the rest of the lines in the second file are unique to it. Then you're done. Else, read a line from the first file and goto 5.
        7. The line from the second file is unique to it. If you have exhausted the second file, the rest of the first file are lines unique to it, and you're done. Else read the line from the second file and goto 5.
        Translating that to Perl is left as an exercise to the user who gets paid for it.