LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-24-2005, 09:56 PM   #1
webeye
LQ Newbie
 
Registered: Nov 2005
Location: China
Posts: 4

Rep: Reputation: 0
comm question


hello
i use comm to compare two very simple file.
file1:
0
0
1

file2:
0
1
0

comm file1 file2 ---->output:
................0
0
................1
........0



I view comm's man page, the interpretation of output is listed following:

Column one contains lines unique to FILE1, column two contains lines unique to FILE2, and column three contains lines common to both files

But i do not understand how does the result generate above? it seems different from the man page gave. Anyone can tell me what's the rule of comm's comparison or give me a reference? Thank in advance

Last edited by webeye; 11-24-2005 at 10:08 PM.
 
Old 11-25-2005, 08:23 PM   #2
zahadumy
Member
 
Registered: May 2005
Location: Cluj, Romania
Distribution: Fedora Core 6
Posts: 226

Rep: Reputation: 31
That's very weird. I used comm a couple of times and it worked fine for me. I suppose it's a bug and that happens when you have the same line more than one time in a file:
Code:
[cosmin ~]$ cat file1
0
1
2
3
[cosmin ~]$ cat file2
2
3
4
5
[cosmin ~]$ comm file1 file2
0
1
                2
                3
        4
        5
And now this is what I suppose it's a bug:
Code:
[cosmin ~]$ cat file1
0
1
2
3
1
2
[cosmin ~]$ cat file2
2
3
4
5
1
2
[cosmin ~]$ comm file1 file2
0
1
                2
                3
1
2
        4
        5
        1
        2
My opinion is that you have nothing to understand here. If I were you, I would write a C program which does this.
 
Old 11-26-2005, 11:02 AM   #3
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Sigh. If you read the man page for comm you might notice the words "compare two sorted files line by line". Note the word "sorted". The bug is in your use of comm, not in the code itself.
 
Old 11-26-2005, 11:07 AM   #4
zahadumy
Member
 
Registered: May 2005
Location: Cluj, Romania
Distribution: Fedora Core 6
Posts: 226

Rep: Reputation: 31
Good point. Thank you eddiebaby1023.
 
Old 11-27-2005, 01:11 PM   #5
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Quote:
Originally posted by zahadumy
Good point. Thank you eddiebaby1023.
I got bitten the first time I used comm.
 
Old 11-27-2005, 09:39 PM   #6
webeye
LQ Newbie
 
Registered: Nov 2005
Location: China
Posts: 4

Original Poster
Rep: Reputation: 0
First, thank you for zahadumy and eddiebaby1023 very much.

Second, I see that the two file must be sorted. but i don't understand what does the mean of "line by line"?

etc:
file1
0
1

file2
1
2

comm output
0
...................1
...........2

Who can describe the output of comparable process of simple example above?
 
Old 11-28-2005, 04:06 AM   #7
zahadumy
Member
 
Registered: May 2005
Location: Cluj, Romania
Distribution: Fedora Core 6
Posts: 226

Rep: Reputation: 31
Quote:
Originally posted by webeye
First, thank you for zahadumy and eddiebaby1023 very much.

Second, I see that the two file must be sorted. but i don't understand what does the mean of "line by line"?

etc:
file1
0
1

file2
1
2

comm output
0
...................1
...........2

Who can describe the output of comparable process of simple example above?
It compares the file line by line, as you can see. On the first column you see lines which appear only in the first file, on the second column lines which appear only in the second file and on the third one lines common to both files. For more details:
Code:
man comm
info comm
"info comm" displays the complete manual

Last edited by zahadumy; 11-28-2005 at 04:07 AM.
 
Old 11-28-2005, 10:41 AM   #8
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
they must be sorted first.

Quote:
The comm utility will read file1 and file2, which should be
ordered in the current collating sequence, and produce three
text columns as output: lines only in file1; lines only in
same goes for 'uniq'
 
Old 11-28-2005, 07:57 PM   #9
webeye
LQ Newbie
 
Registered: Nov 2005
Location: China
Posts: 4

Original Poster
Rep: Reputation: 0
`comm' writes to standard output lines that are common, and lines that are unique

above is the first line of "info comm". Is the part of text bold means the line of file also must unique?

etc:
0
1
-----input is right
0
0

1
-----input is wrong, because the 0 is not unique

is right about my understand above?

Last edited by webeye; 11-28-2005 at 09:46 PM.
 
Old 11-29-2005, 12:49 AM   #10
zahadumy
Member
 
Registered: May 2005
Location: Cluj, Romania
Distribution: Fedora Core 6
Posts: 226

Rep: Reputation: 31
Quote:
Originally posted by webeye
`comm' writes to standard output lines that are common, and lines that are unique

above is the first line of "info comm". Is the part of text bold means the line of file also must unique?

etc:
0
1
-----input is right
0
0

1
-----input is wrong, because the 0 is not unique

is right about my understand above?
No, you can give as input whatever you want, but the file must be sorted.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Comm 5 WillG SUSE / openSUSE 3 09-04-2005 10:16 PM
usb serial comm guyulmaz Mandriva 3 06-07-2005 01:20 AM
which should I use? diff cmp comm Frybyte Linux - Newbie 2 07-19-2004 08:22 AM
urpmi&club.comm lachlan Linux - Software 1 02-26-2003 03:07 AM
java comm api from ibm tda Programming 1 02-10-2003 09:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration