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 10.0.0.5” 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 10.0.0.5” *
__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:
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 10.0.0.5” in them would be:
egrep -LR “logging 10.0.0.5” *
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 10.0.0.5” * | grep configs | grep -v CVS
To get a count of the files returned, sort it and use _uniq_ to filter duplicates…
egrep -LR “logging 10.0.0.5” * | grep -v CVS | grep configs | sort | uniq | wc -l