What is the single command used to identify only the matching count of all lines within files under the /etc
directory that contain the word "HOST"?
I should list only the files with matches and suppress any error messages.
command linegreplinux
What is the single command used to identify only the matching count of all lines within files under the /etc
directory that contain the word "HOST"?
I should list only the files with matches and suppress any error messages.
Best Answer
To count the matches, listing only the filename(s) and count:
Example output:
The
-c
option supresses normal output and prints a match count for each file.If you'd like to suppress the files with zero counts:
To print the line number (
-n
) and file name (-H
) for each matching line for any number of input files:Example output:
The option
-r
causesgrep
to recursively search files in each subdirectory at all levels under the specified directory. The-s
option suppresses error messages.To suppress matches of binary files, use the
-I
option.See
man grep
for more information.