How do I 39grep -c39 and avoid printing files with zero 39039 count

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

The command grep -c blah * lists all the files, like below.

 % grep -c jill *
 file1:1
 file2:0
 file3:0
 file4:0
 file5:0
 file6:1
 % 

What I want is:

 % grep -c jill * | grep -v  :0 
 file1:1
 file6:1
 % 

Instead of piping and grep ing the output like above, is there a flag to suppress listing files with 0 counts?

SJ

Answers

Just use awk. e.g. with GNU awk for ENDFILE:

awk  /jill/{c++} ENDFILE{if (c) print FILENAME":"c; c=0}  *

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/35565533/how-do-i-grep-c-and-avoid-printing-files-with-zero-0-count

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils