Dear Monks,
I am facing a peculiar kind of a problem in printing the common text between the 2 file:-
I tried the Shell commands like
sdiff diff gvimdiff etc but no success
Please help me bcoz its urgent.
My files look like this:-
File 1:- Harry 21 Jeff 45 Rob 78 Mett 34 Ann 17 Gilli 39 DOn 98 Ben 15 Harry 54 Rose 46 Ness 65 File 2:- 2133 32 45 45 CC Old Harry (D) (28%) 21 + -1 Rob (D) (31%) 78 + -1 Met +t (D) (14%) 34 + -1 5789 78 66 32 DD Young Gilli (D) (10%) 39 + -1 Don (D) (66%) 98 + -1 M +ett (D) (23%) 15 + +1 9027 56 77 29 GG Old Harry (D) (10%) 54 + -1 Rose (D) (%) 46 + -1 Ness + (D) (67%) 65 + 1
I have to get my results like this:- If suppose Harry, Rob and Met are present 2133 32 45 45 CC Old Harry (D) (28%) 21 + -1 Rob (D) (31%) 78 + -1 Met +t (D) (14%) 34 + -1 3 3 since all the are matching If only Gilli and Don are present in File 1 then 5789 78 66 32 DD Young Gilli (D) (10%) 39 + -1 Don (D) (66%) 98 + -1 + 2 2 since only 2 are matching 9027 56 77 29 GG Old Harry (D) (10%) 54 + -1 1 Since only 1 is matching with File 1

I am new to scripting so donno how to approach the problem.
I would be obliged to get help from Monks
Bravo ... Here is my code but not getting the output yet :(
#!/usr/bin/perl -w open(FH, "<File1.txt") || die "Cannot open file"; %href; while( FH> ) { chomp($_); $href{$1} = $2 if $_ =~ /(\S+)\s+(\S+)/; } while (my ($key, $value) = each(%href)) { #print $key. ", ". $value."\n"; } close FH; open(FD, "<File2.txt") || die "Cannot open file"; while(<FD>) { chomp; next unless ( s{ \s+(\w+)\s+\([A-Z]\)\s+\(\d*%\)\s+\d\s+\+ +\s[+-]?\d+}{}xms and exists( $href{$1} )); my $name = $1; print "$name\t\t$href{$name}\n"; #@_=split('\t',$_); }

Thanks

In reply to File Intersection problem by ashnator

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.