in reply to Re^2: compare a list from one file with another text file
in thread compare a list from one file with another text file

Arunbear already provided an efficient solution, but if you are interested, here is the reason why your version didn't work:

1) First of all there is a '}' missing at the end, but I guess this is the fault of the copy and paste

2) For every line in data.txt you reread all.txt, grep for the result and then write the data into requery.txt (highly inefficient but a working idea). Sadly every time you open requery.txt again you delete the previous version of requery.txt, so that eventually only the last result is in there. Your program would work by simply changing the '>' in
open (FASTA, ">requery.txt" ...
to '>>'

Even better would be to open requery.txt before the foreach loop (same place where you open data.txt). That way it gets opened only once

Replies are listed 'Best First'.
Re^4: compare a list from one file with another text file
by sm2004 (Acolyte) on Apr 06, 2008 at 04:10 UTC
    Thanks a lot. That was very helpful. It works now. I really appreciate all the feedback.