Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: compare two text files

by prasadbabu (Prior)
on Jul 14, 2005 at 05:29 UTC ( [id://474755]=note: print w/replies, xml ) Need Help??


in reply to Re^2: compare two text files
in thread compare two text files

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

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

Prasad

Replies are listed 'Best First'.
Re^4: compare two text files
by juergenkemeter (Novice) on Jul 14, 2005 at 05:59 UTC
    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

      The problem is, you have to include the option modifier 'i' to ignore case. Because in your gen.txt file 'AT' is present and in search file 'at' is present.

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

      Now it will work fine.

      Prasad

Re^4: compare two text files
by Anonymous Monk on Aug 22, 2007 at 13:18 UTC
    that's good code shraddha rusia starletexports

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://474755]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-03-28 18:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found