Kim,
Is the txt coming in as a list of words? or is it a string of words. If it is a string of words then FirstPosition will not work. You need to use String searching instead of list searching.
I'll assume you are using a list of words like this:
wordlist = {"aaa", "bbb", "ccc", "bbb", "ddd", "eee", "fff", "ggg", "hhh",
"fff", "iii"}
The operation you describe is recursive -- you want to find a string starting at a word and search within that substring.
First we find a substring with one key word (the keyword is in a list all by itself)
finder[lst_, {lastone_}] :=
Drop[lst, First[FirstPosition[lst, lastone]]]
Now overload the function to operate on the first keyword and recursively send the result to the function for the rest of the keywords:
finder[lst_, toFind_List] :=
finder[finder[lst, {First[toFind]}], Rest[toFind]]
Now we can use it:
keywords = {"bbb", "ddd", "fff"};
finder[wordlist, keywords]
To get
{"ggg", "hhh", "fff", "iii"}
We searched for the "bbb", then searched for the "ddd" in the remaining string, then searched for the "fff". To verify what is happening you can call finder sequentially:
In[26]:= n1 = finder[wordlist, {"bbb"}]
Out[26]= {"ccc", "bbb", "ddd", "eee", "fff", "ggg", "hhh", "fff", \
"iii"}
In[27]:= n2 = finder[n1, {"ddd"}]
Out[27]= {"eee", "fff", "ggg", "hhh", "fff", "iii"}
In[28]:= n3 = finder[n2, {"fff"}]
Out[28]= {"ggg", "hhh", "fff", "iii"}
Regards,
Neil
*Edit: simplified the finder definition