Friday, October 16, 2015

Grep to find the lines

Ref: http://unix.stackexchange.com/questions/28158/is-there-a-tool-to-get-the-lines-in-one-file-that-are-not-in-another


The standard grep tool for searching files for text strings can be used to subtract all the lines in one file from another.
grep -F -x -v -f fileB fileA
This works by using each line in fileB as a pattern (-f fileB) and treating it as a plain string to match (not a regular regex) (-F). You force the match to happen on the whole line (-x) and print out only the lines that don't match (-v). Therefore you are printing out the lines in fileA that don't contain the same data as any line in fileB.