Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have 2 files with me having content like:

file1:

a
b
c
e
g
s

and file2

s
a
b
c

I want to compare contents of the file, that what which letters are NOT present in other file, and which Are present in other file. problem is that the size of the files is different. if it would have been same,then it wont be an issue and simple DIFF would give me the comparison.

if i compare file1 and file 2, i need to get the difference like this, following are not present in file 2:

e
g
share|improve this question
    
For the two sample files, could you clarify precisely what you want the output to look like? –  MadHatter Aug 9 '12 at 13:44
    
Generally the answer when you need to figure out if something is missing/added to a file and don't care about the order is to first sort the content and then use diff afterwards. But is that what you want to do? –  pehrs Aug 9 '12 at 13:46
    
i have edited the question –  Farhan Aug 9 '12 at 13:50
    
pehrs, I completely agree, which is why I'm hoping he'll show us the output he'd like to see, based on his sample input files. –  MadHatter Aug 9 '12 at 13:50

2 Answers 2

up vote 1 down vote accepted

Then how's

sort f1 > f1.sort
sort f2 > f2.sort
diff f1.sort f2.sort
4,5d3
< e
< g

That tells you that e and g are present only in f1.

share|improve this answer
    
You can inline sort with <(sort file1) instead of redirect to a temp file. –  quanta Aug 9 '12 at 14:12
    
True, I gleaned that from your answer - very nice! –  MadHatter Aug 9 '12 at 14:16
$ comm -23 <(sort file1) <(sort file2)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.