comm not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting comm not working
# 1  
Old 05-06-2008
comm not working

Hi

Sorry if this a repeat question,

I have the following two files. Both are sorted.

file1
----
CSCeb69473
CSCsg70355
CSCsj78917
CSCsj85065
CSCsl48743
CSCsl72823
CSCsl77748

file2
----

CSCsg39295
CSCsj78917
CSCsj85065
CSCsl72823
CSCsl77748



when I executed "comm -23 file1 file2". Its not showing correctly.

It should show me content in file1 which is not tere in file2. right?

Any idea, why?

Is it that both shud have same number of lines.

Let me know,

Amit
# 2  
Old 05-06-2008
The command
Code:
comm -23 file1 file2

gives me the following output
Code:
CSCeb69473
CSCsg70355
CSCsl48743

I hope this is correct. What is the output you get? Also try comm without any option
Code:
comm file1 file2

# 3  
Old 05-06-2008
Thx kris,

I am getting the following output

> comm -23 file1 file2
CSCeb69473
CSCsg70355
CSCsj78917
CSCsj85065
CSCsl48743
CSCsl72823
# 4  
Old 05-06-2008
You may be using a different version of comm. Check what
Code:
man comm

says.

What unix are you working on? Also verify
Code:
which comm

# 5  
Old 05-06-2008
I am working on Solaris ...SunOS 5.8
# 6  
Old 05-06-2008
Hi.

The combination of bash and comm on Solaris 10 seems to work:
Code:
#!/usr/bin/env bash

# @(#) s1       Demonstrate results from comm.

#  ____
# /
# |   Infrastructure BEGIN

echo
set -o nounset

debug=":"
debug="echo"

## The shebang using "env" line is designed for portability. For
#  higher security, use:
#
#  #!/bin/sh -

## Use local command version for the commands in this demonstration.

set +o nounset
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version =o $(_eat $0 $1) comm
set -o nounset

echo

FILE1=data1
echo " Input file $FILE1:"
cat $FILE1

echo
FILE2=data2
echo " Input file $FILE2:"
cat $FILE2

# |   Infrastructure END
# \
#  ---

echo
echo " Results from processing:"
comm -23 $FILE1 $FILE2

exit 0

Producing
Code:
$ ./s1

(Versions displayed with local utility "version")
SunOS 5.10
GNU bash 3.00.16
comm - no version provided for /usr/bin/comm.

 Input file data1:
CSCeb69473
CSCsg70355
CSCsj78917
CSCsj85065
CSCsl48743
CSCsl72823
CSCsl77748

 Input file data2:
CSCsg39295
CSCsj78917
CSCsj85065
CSCsl72823
CSCsl77748

 Results from processing:
CSCeb69473
CSCsg70355
CSCsl48743

The same results were obtained on Linux 2.6.11 (Debian).

I would next look at the data so see if there are extra non-printing characters ... cheers, drl
# 7  
Old 05-06-2008
I have had problems when sort obeyed my locale but comm did not, or they were used in different locales. Make sure they agree on the sort order. A good safety measure is to use an explicit locale when using commands which care about collation order.

Code:
LC_ALL=C sort
LC_ALL=C comm
LC_ALL=C join
etc

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

comm command help

The manual does not cover this very well. What do the following compares will do ? 1) comm -13 file1 file2: will it display what is in file2 not in file1? 2) comm -23 file1 file2: will it display what in 1 but not in 2 ? Thanks (5 Replies)
Discussion started by: mrn6430
5 Replies

2. UNIX for Dummies Questions & Answers

Need help with comm command

Hello , I am trying to get contents which are only present in a.csv ,so using comm -23 cat a.csv | sort > a.csv cat b.csv | sort > b.csv comm -23 a.csv b.csv > c.csv. a.csv SKU COUNTRY CURRENCY PRICE_LIST_TYPE LIST_PRICE_EFFECTIVE_DATE TG430ZA ZA USD DF ... (4 Replies)
Discussion started by: RaviTej
4 Replies

3. UNIX for Dummies Questions & Answers

help on COMM command please

could some one please explain with examples how comm -12 & comm -3 works. I am confused with manual page, Thankyou. (2 Replies)
Discussion started by: Ariean
2 Replies

4. UNIX for Dummies Questions & Answers

help in comm command

Hi all, I need help in comm command , I am having 2 files . I have to display the common line in the two file only onnce and i have to also display the non common line as well. tmpcut1 -- First file cat tmpcut1 smstr_303000_O_432830_... f_c2_queue_sys30.sys30 RUNNING 10 1000... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

5. Shell Programming and Scripting

problem with using comm

hi, I have two unsorted files and want to delete the lines which are common to both. file 1: S1069656304010437 S1069656304010449 S1470204501005393 S1069656304010474 S0001209208001294 S0000000012345678 S0001457507000590 S0002641707000784 S1470204501005381 S0001457507000280... (4 Replies)
Discussion started by: jathin12
4 Replies

6. Shell Programming and Scripting

comm command

Hi I have issue with "comm " command file-1 ---- l65059 l65407 l68607 l68810 l69143 l71310 l72918 l73146 l73273 l76411 file-2 ----- (8 Replies)
Discussion started by: amitrajvarma
8 Replies

7. Shell Programming and Scripting

comm not working for this case. HELP!

I have two sorted files. newfile has records like: aaa|bbb|ccc||| ddd||eee|fff|| oldfile has records like: aaa|bbb|ccc| ggg||hhh|fff The output should like: ddd||eee|fff|| I use comm but it's not working for this case. comm -2 -3 newfile oldfile > difffile The difffile is the... (6 Replies)
Discussion started by: sslr
6 Replies

8. UNIX for Dummies Questions & Answers

Comm, command help

See my other post on sdiff .... I don't think sdiff is able to do what I want. The 'comm' command does what I need and works fine as far as the logic and results. The problem I'm having is with the output format, it outputs 3 columns of data, but because of the way it starts each line... (2 Replies)
Discussion started by: cowpoke
2 Replies

9. Shell Programming and Scripting

comm with a variable

Hello all, I have two flat files that are colon delineated and I am trying to run a compare (Solaris v8 ksh) of $1 within a script to access a mysql database based on the results. Unix is telling me that it has to have physical file names. Is there a way to run a compare using variables? This is... (3 Replies)
Discussion started by: gozer13
3 Replies

10. Shell Programming and Scripting

comm ?!

Hi, I have two large files with uid's: - 581004 File1.txt - 292675 File2.txt I want to know which uid's are in File1.txt and not in File2.txt. I have used comm -23 File1.txt File2.txt. This should do the trick i thought. But in the output i keep having uid's in File1.txt that are also in... (8 Replies)
Discussion started by: tine
8 Replies
Login or Register to Ask a Question