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.
migrated from stackoverflow.com Nov 1 '10 at 0:55
This question came from our site for professional and enthusiast programmers.
To count the matches, listing only the filename(s) and count:
If you'd like to suppress the files with zero counts:
To print the line number (
To suppress matches of binary files, use the
Its not one command, but it is one line
The question is worded a little odd. First it asks for the amount of lines that match in all the files, then it wants you to list the file names.
To count the matching lines in all files:
grep -R "HOST" /etc 2> /dev/null | wc -l
To list the file names:
grep -Rl "HOST" /etc 2> /dev/null