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
rikxik
2
You need to sort the files before passing to comm. After that comm -3 should be enough to eliminate duplicates.
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??
Something like this???
$ cat file200
S1069656304010437
S1069656304010449
S1470204501005393
S1069656304010474
S0001209208001294
S0000000012345678
S0001457507000590
S0002641707000784
S1470204501005381
S0001457507000280
S147020450100540X
S1069656304010450
$ cat file400
S1069656304010437
S1069656304010449
S1069656304010474
S1069656304010450
$ diff file200 file400 | grep "<" | sed 's/<//g'
S1470204501005393
S0001209208001294
S0000000012345678
S0001457507000590
S0002641707000784
S1470204501005381
S0001457507000280
S147020450100540X
To remove spaces at the beginning....
$ diff file200 file400 | grep "<" | sed 's/<//g' | cut -c 2-
S1470204501005393
S0001209208001294
S0000000012345678
S0001457507000590
S0002641707000784
S1470204501005381
S0001457507000280
S147020450100540X