Compare two files and include both match and non match records

6.9k Views Asked by At

I need to merge two files into one . Suppose I have 2 input files FILE1 and FILE2. And I need to non-matching records from FILE1 and FILE2 into FILE 3 as well as I want to write matching records also into FILE3.If there is matching based on key in FILE1 and FILE2 then matching record to be written must be picked from FILE1/FILE2 on basis of some condition.

The key position in both the Input Files is same.

Can anybody please help me to write SORTCARD, how Can I get this in single step in SyncSort or DFSort??

2

There are 2 best solutions below

4
bp89 On BEST ANSWER

I got my solution using following sort card:

    JOINKEYS F1=IN1,FIELDS=(1,7,A,13,7,A)                     
    JOINKEYS F2=IN2,FIELDS=(1,7,A,13,7,A)                     
    JOIN UNPAIRED,F1,F2                                       
    REFORMAT FIELDS=(F1:1,239,F2:1,239,?)                     
    OPTION COPY                                               
    OUTFIL FNAMES=OUT1,INCLUDE=(479,1,SS,EQ,C'1,2'),          
    IFTHEN=(WHEN=(479,1,CH,EQ,C'1'),                    
          BUILD=(1,239,479,1)),                       
    IFTHEN=(WHEN=NONE,                                  
          BUILD=(240,239,479,1))                      
    OUTFIL FNAMES=OUT2,INCLUDE=(479,1,SS,EQ,C'B'),            
    IFTHEN=(WHEN=(111,1,FS,EQ,NUM,AND,175,1,FS,EQ,NUM),
           BUILD=(1,239)),                            
    IFTHEN=(WHEN=(350,1,FS,EQ,NUM,AND,414,1,FS,EQ,NUM),
           BUILD=(240,239)),                          
    IFTHEN=(WHEN=NONE,                                 
          BUILD=(1,239))                              
1
shravan kumar On

Try using join keys

SORT FIELDS=COPY
JOINKEYS FILES=F1,FIELDS=(1,5,A)
JOINKEYS FILES=F2,FIELDS=(1,5,A)
JOIN UNPAIRED,F1,F2
REFORMAT FIELDS=(F1:1,6,F2:1,80)

in reformat fields, you can mention the fields as you want, i.e.., if you want matching records to be picked from file2 then mention those fileds beside F2: