Is there a UNIX command on par with
sort | uniq
to find string set intersections or “outliers”.
An example application: I have a list of html templates, some of them have {% load i18n %} string inside, others don’t. I want to know which files don’t.
edit: grep -L solves above problem.
How about this:
file1:
mom
dad
bob
file2:
dad
%intersect file1 file2
dad
%left-unique file1 file2
mom
bob
It appears that
grep -Lsolves the real problem of the poster, but for the actual question asked, finding the intersection of two sets of strings, you might want to look into the “comm” command. For example, iffile1andfile2each contain a sorted list of words, one word per line, thenwill produce the words common to both files. More generally, given sorted input files
file1andfile2, the commandproduces three columns of output
You can suppress the column
Nin the output with the-Noption. So, the command above,comm -12 file1 file2, suppresses columns 1 and 2, leaving only the words common to both files.