find lines that matches on 2 different sorted file
Supposed we have 2 sorted files:
file1
1
2
3
4
5
file2
3
4
5
6
7
comm
is a utility for finding lines that appear (or not) between 2 files. The normal output are 3 column. - 1.Lines that is unique on file 1
- 2.Lines that is unique on file 2
- 3.Lines that are appear on both
$ comm file1 file2
1
2
3
4
5
6
7
$ comm -12 file1 file2
3
4
5
-12
supresses (do not include) colunm 1 & 2$ comm -23 file1 file2
1
2
If file is not sorted, you can use the
<(..)
operator$ comm <(sort -u file1) <(sort -u file2)
1
2
3
4
5
6
7
Last modified 9mo ago