Posts linux use comm command to find common lines
Post
Cancel

linux use comm command to find common lines

  • Create first file
1
2
3
4
5
6
7
$ vi file1
1
2
3
4
5

  • Create second file
1
2
3
4
5
6
$ vi file2
2
3
34
35

  • Use comm to find common lines
1
2
3
$ comm -12 file1 file2
2
3

Please make sure that data is sorted in asending order else please use sort command.

1
2
3
4
5
6
7
8
9
10
11
12
13
$ vi file3
23
4
1
2

$ cat file3 | sort -n -o file3

$ cat file3
1
2
4
23
This post is licensed under CC BY 4.0 by the author.