Set Intersection / Set Subtraction

To find lines that are in both of two files (intersection) or in only one of the two files (subtraction), use the following commands:

# intersection of file1 and file2
grep -xF -f file1 file2
 
# subtraction of file1 from file2
grep -vxF -f file1 file2

Trim Commented and Blank Lines

Many Linux configuration files use the hash sign (#) as a comment indicator. The following command:

grep -v -e "^#" -e "^$" /etc/squid3/squid.conf

will remove (-v) all the lines starting with comments (^#) and then additionally will remove blank lines left after the trim (^$) from the file /etc/squid3/squid.conf.