The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
comm not working amitrajvarma Shell Programming and Scripting 7 05-06-2008 11:44 AM
getting problem in my code:::: plz help...(multithreaded appn with serial comm.) arunchaudhary19 High Level Programming 0 10-29-2007 09:38 AM
getting problem in my code:::: plz help...(multithreaded appn with serial comm.) arunchaudhary19 Linux 0 10-26-2007 07:24 AM
comm with a variable gozer13 Shell Programming and Scripting 3 07-13-2005 09:29 PM
comm ?! tine Shell Programming and Scripting 8 12-08-2003 03:52 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-27-2009
jathin12 jathin12 is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 19
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 (permalink)  
Old 02-27-2009
rikxik's Avatar
rikxik rikxik is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 250
You need to sort the files before passing to comm. After that comm -3 should be enough to eliminate duplicates.
  #3 (permalink)  
Old 02-27-2009
jathin12 jathin12 is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 19
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 (permalink)  
Old 02-27-2009
Whiteboard's Avatar
Whiteboard Whiteboard is offline
Registered User
  
 

Join Date: Feb 2009
Location: @........
Posts: 111
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 (permalink)  
Old 02-27-2009
Whiteboard's Avatar
Whiteboard Whiteboard is offline
Registered User
  
 

Join Date: Feb 2009
Location: @........
Posts: 111
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

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0