You can use the
to tell you how many occurrences of a pattern appear
in a given file, so you can also use it to find files that
a pattern (i.e., zero occurrences of the pattern).
Let's say you're indexing a
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
grep -c "\.XX" chapter*
might produce the following output:
This is all well and good, but suppose you need to check index entries in
hundreds of reference pages? Well, just filter
's output by piping it
. The above command can be modified as follows:
grep -c "\.XX" chapter* | grep :0
This results in the following output:
to truncate the
you can save the output as a list of files.
For example, here's a trick for creating a list of files that
contain index macros:
grep -c "\.XX" * | sed -n s/:0//p > ../not_indexed.list
command prints only the lines that contain
it also strips the
from the output so that
contains a list of files, one per line.
file into the parent directory - this is one
easy way to keep
from searching that file, but may not be
worth the bother.
[To edit all files that need index macros added, you could type:
vi `grep -c "\.XX" * | sed -n s/:0//p`
which is more obvious once you start using backquotes a lot.
You can put this into a little script named
with a couple
of safety features added:
case $# in
0|1) echo "Usage: `basename $0` pattern file [files...]" 1>&2 ;;
*) pat="$1"; shift
grep -c "$pat" "$@" | sed -n 's/:0$//p'
Then you can type, for example,
vi `vgrep "\.XX" *`