I have a variable number of text files (between 3-8), each between 20,000 and 30,000 lines long (different lengths), and around 400 words to search for. The words have different lengths.
Let's say I have the following text:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx999xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx12345xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
where xxxxx can be anything other than what I want to search for. I want to make check whether the following is true:
- That each text file includes '12345'
- That for at least one occurrence of '12345' in each file, there is '999'. The end of '999' always coincides with the end of '12345'.
I can determine whether '12345' is in each of the text files using strfind, but strfind only ouputs an "index" value for the first character of my search pattern (e.g. 613587). Is there a way to find the line number that "index" value corresponds with, and search one line above for '999'?
I think I saw people recommending that each line for each file be read as a separate string, then search each string independently, but that seems like a lot of work for MATLAB to go through, having to generate close to a hundred thousand strings. Is there a better/more efficient way of achieving this?
Any help would be appreciated!
Best Answer