© unknownartist@newsgroup

The macro eliminates duplicate records if in immediate sequence. The delimiters of the column for comparison can be specified. If omitted, the boundaries are assumed.

On demand the records can be sorted previously.

/* REXX - #DELDUP EDIT MACRO ***********************************/
/* Remove duplicates from columns i-j (i,j are parameters)     */
/* if i or j are not specified, they default to Boundaries     */
/*-------------------------------------------------------------*/
/* This macro uses one trick to improve performance:           */
/*    Many excludes and a final delete is faster than          */
/*    individual line deletes.                                 */
/*-------------------------------------------------------------*/
Address isredit
"MACRO (LCOL,RCOL)"                      /* macro with 2 parms */
"(LBND,RBND) = BOUNDS"                  /* save old Boundaries */
lbnd = abs(lbnd)
rbnd = abs(rbnd)
"(DW) = DATA_WIDTH"                  /* Tet maximum data width */
if lcol > rcol then do
   lcol = bitxor(lcol,rcol)             /* turn left and right */
   rcol = bitxor(rcol,lcol)
   lcol = bitxor(lcol,rcol)
end
if datatype(lcol,'N')=0 then lcol=lbnd      /* Set left column */
if datatype(rcol,'N')=0 then rcol=rbnd     /* Set right column */
"(LAST) = LINENUM .ZLAST"           /* Get number of last line */
"RESET X"                              /* Un-Exclude all lines */

say "Erst Sortieren j/N (Stelle" lbnd "bis" rbnd")";pull antwort
if antwort="J" then do
   "BOUNDS"                                /* reset boundaries */
   "sort &LBND &RBND A"         /* sort between old boundaries */
   "BOUNDS = (LBND,RBND)"              /* set boundaries again */
end
len=abs(rcol-lcol)+1             /* Get length of compare area */
Do linenum = 1 to last               /* Loop through all lines */
  "ISREDIT (LINE) = LINE "linenum   /* Put line data in 'line' */
  test=substr(line,lcol,len)        /* Take columns to compare */
  If test = testold Then         /* Compare with previous line */
    "ISREDIT XSTATUS "linenum" = X"  /* If match, exclude line */
  testold = test             /* Save current line compare area */
End
"ISREDIT DEL ALL X"           /* Finally, delete excluded lines*/
Exit 1
back to Edit Macros