How can I go through a file, analyze specific words, state which line the those words appear in, which column they start at, and what is the actual line that contains the word?

5 views (last 30 days)
I have to:
1. Open and read a file.
2. Go through each specific word/phrase I am given (one word is case sensitive, the other two are not) and find:
-Which line do these words appear?
-Which column do these words start at?
-What is the actual line that contains this word?
3. Provide a nicely formatted printout to report the above findings.
4. After all of this, I must close the file.
So for example, if the text file is named "file.txt" and the 3 words I am looking for are
Tree (case sensitive)
roller coaster (not case sensitive)
silly (not case sensitive)
How would I go about doing this using while loops/strcmp/strcmpi/strread/strfind/for loops/ if statements?

Answers (1)

Walter Roberson
Walter Roberson on 9 Nov 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!