I need to read a file in a series of lines, and then retrieve specific lines depending on words that are contained in them. How can I do this?
So far I read the lines like this:
lines = File.readlines("myfile.txt")
Now, I need to scan for lines that contain "red", "rabbit", "blue". I want to do this part in as few lines of code as possible.
So if my file was:
the red queen of hearts.
yet another sentence.
and this has no relevant words.
the blue sky
the white chocolate rabbit.
another irrelevant line.
I would like to see only the lines:
the red queen of hearts.
the blue sky
the white chocolate rabbit.