in reply to compare two text files

If i understood your question correctly this should work for you. This can be done still efficiently.

open (GEN, "<general.txt") || die ("cannot open general.txt"); open (SEA, "<search.txt") || die ("cannot open search.txt"); undef $/; $gen = <GEN>; $sea = <SEA>; @gen = split /\n/, $gen; @sea = split /\n/, $sea; for $a (@gen) { @result = grep/^\Q$a\E$/, @sea; push (@final , @result); } print "Search string that matches against general data:\t@final";

Prasad

Replies are listed 'Best First'.
Re^2: compare two text files
by juergenkemeter (Novice) on Jul 14, 2005 at 05:19 UTC
    Hi,thanks for your code. I tested it and it seems that it only works for whole strings. Can it be changed so that it also searches for substrings in the 'general.txt' - file? And since I am a beginner, a few explaining words about your code would be very helpful, thanks! Jurgen

      You just remove the anchors ^ and $ to match the substrings.

      @result = grep/\Q$a\E/, @sea;

      Prasad

        Hi, I have tried the following code for substring search, but it still only works for full strings:
        open (GEN, "<general.txt") || die ("cannot open general.txt"); open (SEA, "<search.txt") || die ("cannot open search.txt"); undef $/; $gen = <GEN>; $sea = <SEA>; @gen = split /\n/, $gen; @sea = split /\n/, $sea; for $a (@gen) { # no SUBSTRINGS: @result = grep/^\Q$a\E$/, @sea; @result = grep/\Q$a\E/, @sea; push (@final , @result); } print "Search string that matches against general data:\t@final";
        ////////////////////////////////////////////////////////// here is the content of 'general.txt': AT1G01450 AT1G12680 AT1G20650 AT1G30640 AT1G33770 AT1G49580 AT1G50140 ////////////////////////////////////////////////////////// here is the content of 'search.txt': At1g28530 At1g28530 At1g55090 At2g14580 1450 ////////////////////////////////////////////////////////// the program should recognize '1450' as substring of the first line of 'general.txt' and give out the whole first line of 'general.txt', right? Jurgen
        that's good code shraddha rusia starletexports