Finding a file without a particular line in it

So, I’m starting to use the wonderful package RANCID for grabbing our configs and backing them up. I was looking for a simple way of finding files that didn’t have a particular line in them.

In this example I’ll be looking for things that don’t have “logging” in them. The logging command sends syslog on Cisco routers to a remote device. This isn’t actually our syslog or search server, but I’m probably better off not posting those details 🙂

grep -vR “logging” *

__Will show you all lines in all file (recursively) that don’t match the search term. Nope

I peered through awk and sed to try and do funky things, not thinking to check egrep.

man egrep led me to this:

-L, -files-without-match

Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning will stop on the first match.

So, the command to recursively search and return all files without the line “logging” in them would be:

egrep -LR “logging” *

I was searching multiple directories and only wanted files in the config directory, and ignore files in the CVS dirs so I included extra filters:

egrep -LR “logging” * | grep configs | grep -v CVS

To get a count of the files returned, sort it and use _uniq_ to filter duplicates…

egrep -LR “logging” * | grep -v CVS | grep configs | sort | uniq | wc -l

#egrep #find #grep #Linux #search