15.8 Getting a List of Non-Matching Files with grep -c
You can use the
grep
(
27.2
)
option
-c
to tell you how many occurrences of a pattern appear
in a given file, so you can also use it to find files that
don't
contain
a pattern (i.e., zero occurrences of the pattern).
Let's say you're indexing a
troff
(
43.13
)
document and you
want to make a list of files that don't yet contain indexing macros. What
you need to find are files with zero occurrences of the string
% might produce the following output:
chapter1:10 chapter2:27 chapter3:19 chapter4:0 chapter5:39 ... This is all well and good, but suppose you need to check index entries in hundreds of reference pages? Well, just filter grep 's output by piping it through another grep . The above command can be modified as follows:
% This results in the following output:
chapter4:0
Using
sed
(
34.24
)
to truncate the
%
The
sed -n
command prints only the lines that contain [To edit all files that need index macros added, you could type:
% which is more obvious once you start using backquotes a lot. You can put this into a little script named vgrep with a couple of safety features added:
Then you can type, for example,
- |
|