CMP - Comm Command in Linux

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

cmp and comm commands

-------------------[root@Server1 ~]# cmp file.1 file.2


file.1 file.2 differ: byte 22, line 1
[root@Server1 ~]#

compare and check its exist status only


---------------------------------------[root@Server1 ~]# cmp -s file.1 file.2
[root@Server1 ~]# echo $?
1
[root@Server1 ~]#

what is comman
-------------comm - compare two sorted files line by line
Compare sorted files FILE1 and FILE2 line by line.
[root@Server1 ~]# cat a.txt
sl-9023
sl-2112
sl-9029
sl-1210
sl-1215
[root@Server1 ~]# cat b.txt
sl-9029
sl-9023
sl-1215
sl-2112
sl-9012
sl-9016
[root@Server1 ~]#
Using bash process substitution technique (without creating those temporary fil
es)
-----------------------------------------------------------------------------------

[root@Server1 ~]# comm -12 <(sort a.txt) <(sort b.txt)


sl-1215
sl-2112
sl-9023
sl-9029
[root@Server1 ~]#

[root@Server1 ~]# comm a.txt b.txt


sl-9023
comm: file 1 is not in sorted order
sl-2112
sl-9029
comm: file 2 is not in sorted order
sl-1210
sl-1215
sl-9023
sl-1215
sl-2112
sl-9012
sl-9016
[root@Server1 ~]#

but above output is wrong

Lets sort the files


------------------[root@Server1 ~]# sort -o /tmp/srt.a.txt a.txt
[root@Server1 ~]# sort -o /tmp/srt.b.txt b.txt
[root@Server1 ~]#

[root@Server1 tmp]# comm -12 srt.a.txt srt.b.txt


sl-1215
sl-2112
sl-9023
sl-9029
[root@Server1 tmp]#

You might also like