Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
144 views

CMP - Comm Command in Linux

The document discusses the cmp and comm commands in Linux. Cmp is used to compare two files and check for differences, while comm is used to compare sorted files line by line. The comm command requires sorted input files, and using process substitution with sort allows comm to be run without creating temporary files by sorting the input files within the command.

Uploaded by

manazar
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views

CMP - Comm Command in Linux

The document discusses the cmp and comm commands in Linux. Cmp is used to compare two files and check for differences, while comm is used to compare sorted files line by line. The comm command requires sorted input files, and using process substitution with sort allows comm to be run without creating temporary files by sorting the input files within the command.

Uploaded by

manazar
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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