Say I have a directory that contains other directories and files. I want to search for a string in each file and copy only the matching lines to another location while preserving directory structure.
For example, say I have this structure
dir
subdir1
file1.txt
subdir2
file2.txt
and
file1.txt:
abc
def
and
file2.txt:
ghi
Now I want to get only matching lines from the files that contain 'de', so the outcome I want should look like this:
dir
subdir1
file1.txt
subdir2
and
file1.txt
def
bash) than a Linux question: you may consider posting it on StackOverflow instead. (However I won't flag anything here as some people will think of a conditionalgrep-supportedfindto do just that there :) ).