Issue
I'm trying to pull the lines from text files scattered in tens of thousands of subdirectories which contain [surname] from 15 text files of ~100 lines each in the format:
or
[firstname] [middlename] [surname]
So carry out the ~1500 searches into all subdirectories and compile all of the lines into one single file surnames.txt
Thank you.
Solution
If all files in the directory (and subdirectories) are only the .txt files you want to search, then the following should suffice.
grep surname -rh . > surnames.txt
where the flags mean:
-r
recursively searches subdirectories.-h
prevents the filename from being printed out.
If not all files are .txt files, you should narrow your search to only .txt files using find:
find . -name \*.txt -exec grep surname -h {} + > surnames.txt
If this is something you're gonna do often, you should look into doing this search in parallel, something akin to this.
Answered By - Sagar Answer Checked By - Candace Johnson (WPSolving Volunteer)