Page 1 of 1

Compare 2 files and eliminate duplicates

PostPosted: Sun Dec 07, 2008 5:44 am
by alanmdc
Hello,

Can you please help me on my problem :)
Basically I have 2 files; first one is the master list and the second file is the exclude list.
What I want to do is sort out all the records in the master list exluding all the records found in the exclude list.
Ex.
File1 (unsorted)
012345AAAA11112222
013456BBBB22223333
012345AAAA11114444
013456BBBB11116666
012345AAAA33334444
014567CCCC11115555
013456BBBB11113333
012345AAAA22227777

File2 (sorted)
11113333
11115555
22223333
22227777

I expect to produce an output below
OutFile
compare file1 (col 11-18) against file2 (col 1-8)
(sorted from column 1-6)
012345AAAA11112222
012345AAAA11114444
012345AAAA33334444
013456BBBB11116666

Thanks in advance for the help :)

Regards,
AlanMDC
http://www.alanmdc.hobby-site.com

Re: Compare 2 files and eliminate duplicates

PostPosted: Sun Dec 07, 2008 6:26 am
by Frank Yaeger
Here's a DFSORT/ICETOOL job that will do what you asked for. I assumed input file1 has RECFM=FB and LRECL=18 and input file2 has RECFM=FB and LRECL=8, but the job can be changed appropriately if the files have different attributes. I also assumed that input file2 could have keys not found in input file1 (even though your example doesn't show that). If that assumption is incorrect, then the job could be simplified a bit.

//S1   EXEC  PGM=ICETOOL
//TOOLMSG   DD  SYSOUT=*
//DFSMSG    DD  SYSOUT=*
//IN1 DD DSN=...  input file1 (FB/18)
//IN2 DD DSN=...  input file1 (FB/8)
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(MOD,PASS)
//T2 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//OUT DD DSN=...  output file (FB/18)
//TOOLIN DD *
COPY FROM(IN1) TO(T1) USING(CTL1)
COPY FROM(IN2) TO(T1) USING(CTL2)
SELECT FROM(T1) TO(T2) ON(11,8,CH) NODUPS USING(CTL3)
SORT FROM(T2) TO(OUT) USING(CTL4)
/*
//CTL1CNTL DD *
  INREC OVERLAY=(19:C'1')
/*
//CTL2CNTL DD *
  INREC BUILD=(11:1,8,19:C'2')
/*
//CTL3CNTL DD *
  OUTFIL FNAMES=T2,INCLUDE=(19,1,CH,EQ,C'1')
/*
//CTL4CNTL DD *
  SORT FIELDS=(1,6,CH,A)
  OUTREC BUILD=(1,18)
/*