The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 11-28-2005
krsunderm krsunderm is offline
Registered User
 

Join Date: Nov 2005
Posts: 1
comm - sorted result issues

In AIX 5.2, we are attempting to create a delta file by comparing the prior extract to the new extract. We are having some records appear as new when we wouldn't expect it.

Problem appears to be related to the appearance of a new record with a key that is wholly contained in another records key. (Not sure why the key would even matter since we are performing record-level comparisons...)

Ultimately looking to understand:
1) Why are we getting the additional records back?
2) Why does the sort -n (noted below) resolve the issue?


An example probably illustrates the issue best... NOTE(Both sorts use the same syntax.)

Previous Extract (sorted result named prev_extract.dat.srt)
11111|Value A1|Value A2
12345|Value A3|Value A4
12346|Value A5|Value A6
9999|Value A7|Value A8

New Extract (pre-sort)
11111|Value A1|Value A2
12345|Value A3|Value A4
12346|Value A5|Value A6
9999|Value A7|Value A8
123|Value A9|Value A10

Sort New Extract
sort -t"|" -k1,1 New_Extract.dat > New_Extract.dat.srt

New Extract (sorted result)
11111|Value A1|Value A2
123|Value A9|Value A10
12345|Value A3|Value A4
12346|Value A5|Value A6
9999|Value A7|Value A8

Compare the Files
comm -23 New_Extract.dat.srt prev_extract.dat.srt > Extract_addchg.dat


Based on our understanding, the comparison results should show any records that are new (adds) or have been modified. So Extract_addchg.dat should look like:
123|Value A9|Value A10

However, our Extract_addchg.dat actually looks like:
123|Value A9|Value A10
12345|Value A3|Value A4
12346|Value A5|Value A6


If we change our sort commands to a sort -n ... then the 123 record moves well before the 12345 and 12346 and the comm only returns the records desired.


Any explanations?
Reply With Quote
Forum Sponsor