Searching for a phrase in a text file

lukeaarond lukeaarond at gmail.com
Wed Jul 6 00:07:47 CEST 2011


I have a text document with a lot of information in it, but I just need to
extract one sequence from it. Right before the sequence is always the phrase
'ncbi2na' and ends with an apostrophe, therefore, I want to search the whole
file for 'ncbi2na' and save the data until the end apostrophe. The text file
looks like the following:

....'junk'....
....'junk'....
....'junk'....
....'junk'....
....'junk'....
....'junk'....
ncbi2na ATTTGAATGCCAA'H
....'junk'....
....'junk'....

I am currently doing this by parsing each character until it sees the
characters n,c,b,i,2,n and a, next to eachother. As shown below:

fd=mopen(Filename,"r");
while ~meof(fd)
    character(i)=mgetstr(1,fd)
    //then various code to save information after ncbi2na and before the
apostrophe
end
mclose(fd)

However, since there is about 1000 rows of 'junk' before the sequence, it
takes a very long time to parse through and find the sequence.

Therefore, I was wondering if there is a quicker way? Perhaps a function or
method that allows me to "search" through the file until I find 'ncbi2na'
and start my parsing from there. Thank you in advance.

--
View this message in context: http://mailinglists.scilab.org/Searching-for-a-phrase-in-a-text-file-tp3142731p3142731.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.



More information about the users mailing list