problem with using comm


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem with using comm
# 1  
Old 02-27-2009
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
S147020450100540X
S1069656304010450


file 2:
S1069656304010437
S1069656304010449
S1069656304010474
S1069656304010450

code :
comm -23 file1 file2

results in

S1470204501005393
S1069656304010474
S0001209208001294
S0000000012345678
S0001457507000590
S0002641707000784
S1470204501005381
S0001457507000280
S147020450100540X
S1069656304010450


But still two lines that are common are not removed.
S1069656304010474
S1069656304010450

Can ne one help me how to remove all the lines that are common to both?
i am using tcsh
# 2  
Old 02-27-2009
You need to sort the files before passing to comm. After that comm -3 should be enough to eliminate duplicates.
# 3  
Old 02-27-2009
yeah i can sort and then use it.


As i will be using the comm frequently. i need to sort many of such files which has to be comm 'ed later. which creates many temp files.

Ne other method that can delete lines that are common in two files??
# 4  
Old 02-27-2009
Something like this???

Code:
$ cat file200
S1069656304010437
S1069656304010449
S1470204501005393
S1069656304010474
S0001209208001294
S0000000012345678
S0001457507000590
S0002641707000784
S1470204501005381
S0001457507000280
S147020450100540X
S1069656304010450
 
$ cat file400
S1069656304010437
S1069656304010449
S1069656304010474
S1069656304010450

Code:
$ diff file200 file400 | grep "<" | sed 's/<//g'
 S1470204501005393
 S0001209208001294
 S0000000012345678
 S0001457507000590
 S0002641707000784
 S1470204501005381
 S0001457507000280
 S147020450100540X

# 5  
Old 02-27-2009
To remove spaces at the beginning....

Code:
$ diff file200 file400 | grep "<" | sed 's/<//g' | cut -c 2-
S1470204501005393
S0001209208001294
S0000000012345678
S0001457507000590
S0002641707000784
S1470204501005381
S0001457507000280
S147020450100540X

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. UNIX for Dummies Questions & Answers

Not sure how to use diff and comm for my problem

Hello, Apologies if this question has been repeated before, but I am getting myself confused even more as I scan the posts! I have two files, file1 is a column: 1dlwa_ 1s69a_ 1idra_ 1ngka_ And file2 has three columns (columns seperated by tabs): 1dlw a_ A 1uvy a_ A 1dly a_ A 1uvx... (1 Reply)
Discussion started by: InfoSeeker
1 Replies

5. Shell Programming and Scripting

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 (7 Replies)
Discussion started by: amitrajvarma
7 Replies

6. Programming

getting problem in my code:::: plz help...(multithreaded appn with serial comm.)

hello, here I am copying my code... I am using two threads for reading and writing at com ports....one for reading and one for writing...in read thread I am using select() api....and polling again and again if there is some data to be read....but select is not returning any positive value so... (0 Replies)
Discussion started by: arunchaudhary19
0 Replies

7. Linux

getting problem in my code:::: plz help...(multithreaded appn with serial comm.)

hello, here I am copying my code... I am using two threads for reading and writing at com ports....one for reading and one for writing...in read thread I am using select() api....and polling again and again if there is some data to be read....but select is not returning any positive value so... (0 Replies)
Discussion started by: arunchaudhary19
0 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