0

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
Farhan
  • 4,269
  • 11
  • 49
  • 80
  • For the two sample files, could you clarify **precisely** what you want the output to look like? – MadHatter Aug 09 '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 09 '12 at 13:46
  • i have edited the question – Farhan Aug 09 '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 09 '12 at 13:50

2 Answers2

2
$ comm -23 <(sort file1) <(sort file2)
quanta
  • 51,413
  • 19
  • 159
  • 217
1

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.

MadHatter
  • 79,770
  • 20
  • 184
  • 232