Linux – How to Diff Two Config Files

configurationdiff()linux

I've got two snmpd.conf files, one on a server that works, and one that doesn't. How can I diff the two config files while stripping out irrelevant comments and newlines?

Best Answer

diff <(grep -v '^#' f1) <(grep -v '^#' f2)

To avoid blank lines, and lines containing nothing but spaces, in addition to identical lines that have a single difference of added leading spaces...

diff -b \
  <(grep -vE '^([ \t]*#|^[ \t]*$)' f1)\
  <(grep -vE '^([ \t]*#|^[ \t]*$)' f2)

By this point though, I'd probably put that into a script and write something like the original suggestion that's a little more readable.