* * DELDUPL.KEX * * Delete duplicate lines in a file. Compare each line between two columns. * The data file does NOT have to be sorted for this macro to work. * * Works with: * * KEDIT for Windows 1.5 * KEDIT 5.0 for DOS * KEDIT 5.0 for OS/2 * * By default, lines are compared between columns 1 and 80 to determine * duplicates. You can override this on the command line it you want to. For * example, * * deldupl 30 50 * * will cause the macro to compare lines between columns 30 and 50 inclusive. * parse arg LeftCol RightCol if LeftCol = "" & RightCol = "" then do * Use default columns LeftCol = 1 RightCol = 80 end if datatype(LeftCol) \= "NUM" | datatype(RightCol) \= "NUM" then do 'emsg DELDUPL Error 1: Invalid columns specified "'LeftCol RightCol'"' exit 1 end if RightCol > width.1() then do RightCol = width.1() say "Specified right column > WIDTH setting... adjusted to" RightCol end if LeftCol > RightCol then do 'emsg DELDUPL Error 2: Specified left column > right column "'LeftCol RightCol'"' exit 1 end "preserve" "autosave off" ":1" "set zone" LeftCol RightCol * Refresh the screen every 100 lines processed RefreshInterval = 100 n = 0 NumDups = 0 * Loop to process all lines of the file do forever CompareLine = substr(curline.3(), LeftCol, RightCol-LeftCol+1) if n = RefreshInterval then do n = 0 "refresh" end else n = n + 1 * Display all lines that match the current compare field if CompareLine = "" then "nomsg all blank" else "nomsg all" delimit(CompareLine) * Remember where we are for the next iteration "point .LastLine" NumDups = NumDups + (nbscope.1() - 1) "down 1" * Delete the current line and all visible lines below it, i.e., delete * any duplicates "nomsg delete *" * Redisplay all lines "all" * Go to the next line to use as a comparitor ".LastLine" "down 1" * Done? if focuseof() then leave end "all" "top" "restore" say NumDups "duplicate lines have been deleted..." exit 0