I'm not sure how to approach this - I'm trying to create a script that will read through every file in a given directory take any lines containing a certain string, let's say 'bla', and copy them to a new file, giving me a file just with lines containing the string I'm searching for.
I'm not even sure where to look at the documentation.. If someone could point me in the right direction or give me some sample code I'd greatly appreciate it.
There is no need to use ruby for this; you can simply use grep
:
grep -hr "search-string" /path/to/directory/ > output_file
Where -h is the parameter to hide the filename, and -r searches the directory recursively. As from man grep
:
-h, --no-filename
Suppress the prefixing of file names on output. This is the default when there is only one file (or only standard input) to search.
-R, -r, --recursive
Recursively search subdirectories listed.