Only output the name of file containing a pattern (without the line output) using grep
3
votes
2
answers
1866
views
I want to list the files that contain a pattern,
without outputting the line(s) containing the pattern.
I assume that it's possible to do this with
grep
.
How should I use grep
in that sense?
For example, the following command
gives all the lines containing "stringpattern" (case insensitive)
in all the .txt
files.
I want to have only the name of the file (± the line number).
grep -ni stringpattern *.txt
Ideally, if the string/pattern is present more than once in one file,
I would like to have multiple lines of output for that file.
Asked by ecjb
(475 rep)
Jan 30, 2022, 02:12 PM
Last activity: Feb 1, 2022, 11:48 PM
Last activity: Feb 1, 2022, 11:48 PM