Need a script to find sentences or lines in a directory of text files on a hard drive and save the searched terms to a new text file with that name. Must be able to search recursive nested folders.
For example, a hard drive directory is called /archives/ and in it are 4 subdirectories called
In each folder named after a year there are 12 monthly titled folders
In every level of subdirectory there are numerous text files. We need a script to search all these files for a specific term (like blue widgets) and save the sentences or lines (if there is a line break) where that term is found in a text file called "blue [url removed, login to view]" in the top directory searched (/archives/). It will search for all instances of the keyword(s) in the sentence. In the above example, it would retrieve and format the results as follows:
blue [url removed, login to view]
Sales results of blue widgets.
Blue and red widget customers.
Blue widgets sold by quarter.
To recap, your program will have two variables - folder to search for and search term. It will search each sentence or line in a text file and save that line or sentence in a text file named after the search term.
Doesn't matter what language the script is written in as long as it works without crashing or hanging. There are hundreds of text files in each directory.