I would like to search for the term "Liszt" within the contents of all text files except their file name. So if there was a file called Liszt Mazeppa.txt
it should not be matched as the term "Liszt" is in the file name.
Conversely if there were a file called "Masur LGO.txt" whose contents were Beethoven 3; Liszt Orpheus
this should be matched.
I would not use find as from how I understand it find is used for searching for file names.
I tried:
grep -TiPr --include="*.txt" "Liszt" > ./ matches.txt
Unfortunately this still matches text files which have the word Liszt in them.
2
Answers
Assuming you want the filenames of the files containing the word
Liszt
edit
Your rewritten question does not add much.
If you really don’t care about the filenames you can remove the
-name
condition from the previousfind
.Consider what you want when a file whose name contains
Liszt
also hasLiszt
in its content.Regarding
I would not use find as from how I understand it find is used for searching for file names.
– your use of GNUgrep
‘s messy options to both find files and search within files is confusing you.Don’t use
grep
to find files, there’s a perfectly good tool to find files with a very obvious name,find
. The GNU guys really messed up when they gave GNU grep-r
and all those other options for finding files thereby giving people the possibility of makinggrep
commands unnecessarily convoluted.Finding files and searching within files are 2 conceptually separate things so use
find
to find files and thengrep
to g/re/p (Globally match a Regular Expression and Print the result) within files.I’m just guessing at the
grep
options you’ll want from reading your existing code since you didn’t provide any expected output.