* * DELDUP.KEX * * Delete duplicate, contiguous lines in a file. Compare each line between * two columns. The data file must 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, * * deldup 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 DELDUP 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 DELDUP Error 2: Specified left column > right column "'LeftCol RightCol'"' exit 1 end "preserve" "autosave off" ":1" NumDups = 0 * Loop to process all lines of the file do forever CompareLine = substr(curline.3(), LeftCol, RightCol-LeftCol+1) "down 1" * Loop to delete all duplicates of one particular line do forever * Have we hit the end of the file? if focuseof() then leave * Is this a duplicate? if CompareLine \== substr(curline.3(), LeftCol, RightCol-LeftCol+1) then leave "delete 1" NumDups = NumDups + 1 end if focuseof() then leave end "top" "restore" say NumDups "duplicate lines have been deleted..." exit 0