Hello sabas,

Welcome to the Monastery. The fellow Monks have already suggested solutions to your question. I just wanted to add one more by using a module.

A few days ago a similar question was asked find common data in multiple files. I think the best approach is to use the module setop to compare the files and to capture output easily you can do it with IPC::System::Simple.

Sample of code below:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use IPC::System::Simple 'capture'; my $cmd = "setop --intersect " . join " ", @ARGV; chomp (my @output = capture( $cmd )); my %hash; $hash{$ARGV[1]} = \@output; print Dumper \%hash; __END__ $ perl test.pl file1.txt file2.txt $VAR1 = { 'file2.txt' => [ 'Sample line 1', 'Sample line 2', 'Sample line 3', 'Sample line 4', 'Sample line 5', 'Sample line 6', 'Sample line 7', 'Sample line 8', 'Sample line 9', 'Sample line 10' ] };

I do not know if this module is the fastest or the more efficient solution but you can Benchmark.

Input data that I used to replicate your question, file1.txt

Sample line 1 Sample line 2 Sample line 3 Sample line 4 Sample line 5 Sample line 6 Sample line 7 Sample line 8 Sample line 9 Sample line 10

Input data that I used to replicate your question, file2.txt

Sample line 1 Sample line 2 Sample line 3 Sample line 4 Sample line 5 Sample line 6 Sample line 7 Sample line 8 Sample line 9 Sample line 10 Sample line 11 Sample line 12 Sample line 13 Sample line 14 Sample line 15 Sample line 16 Sample line 17 Sample line 18 Sample line 19 Sample line 20

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: searching in large file by thanos1983
in thread searching in large file by sabas

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.