in reply to find common lines in many files

So something must have gone wrong here...

If one file contains more than one instance of any given line, then your count will reach ten even if it is only seen in 9 files. (BTW: Why test for numeric equality with a regex?)

For upto 32 files (Or 64 if you have 64-bit ints) then you could use something like this (untested):

#! perl -slw use strict; my $n = 2 ** @ARGV - 1; my %hash; for my $i ( 0 .. $#ARGV ) [ open my $in, '<', $ARGV[ $i ] or die "$ARGV[ $i ] : $!"; while( <$in> ) { chomp; ( vec( $hash{ $_ }, 1, $i ) |= 1 ) == $n and print; } }

It's not easy to cast that as a one-liner because of the need to know which input file you are dealing with.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: find common lines in many files
by BrowserUk (Patriarch) on Jul 11, 2011 at 09:45 UTC

    Update: Corion points out that you aren't counting. I think your one-liner might work if you modify your regex to be:

    perl -ne 'print if ($seen{$_} .= @ARGV) =~ /^9876543210$/' FILE1 FILE2

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      No, because if lines occur more than once in a file you get strings like "9987655433321"

        Right!


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.