Reputation: 339
I am running grep -r to look for the context of a word in multiple files.
I am using -r to do it recursively, -i to ignore case and -C to get lines below and above:
grep -r -i -C 10 --group-separator="==========" "29/04/2020" "$dir" >> output.txt
In my output, however, I get the filenames before the match, like:
../data/filename1.txt- (other text)
../data/filename1.txt- 29/04/2020 is the date for etc
../data/filename1.txt- (other text)
==========
../data/different_filename.txt- (other text)
../data/different_filename.txt- something in 29/04/2020
../data/different_filename.txt- (other text)
I would like as output just:
(other text)
29/04/2020 is the date for etc
(other text)
==========
(other text)
something in 29/04/2020
(other text)
Do you know how I could alter the grep -r command to exclude the filepaths?
Upvotes: 2
Views: 493
Reputation: 12347
Use grep -h
, as described in 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.
SEE ALSO:
Get grep
to not output file name
Upvotes: 3