(view source code of unique.rex as plain text)
/* Remove double lines from a text file *//* Check command line arguments */Parse Arg clargs
If clargs = "" Then Call Syntax
If Pos( "?", clargs ) > 0 Then Call Syntax
Parse Value clargs With source target dummy1"/"switch dummy2
SelectWhen dummy1 <> "" Then Call Syntax
When dummy2 <> "" Then Call Syntax
When switch <> "" Then Do
If Translate( switch ) = "I" Then case = 0; Else Call Syntax
EndOtherwise case = 1
EndIf target = "" Then target = source
/* Hide standard error */"@ECHO OFF"Trace Off
/* Check if specified files exist */If Stream( source, "C", "QUERY EXISTS" ) = "" Then Call Syntax
/* Read the source file */"CLS"Say "Reading source file . . ."
If LineIn( source, 1, 0 ) = "NOTREADY" then Do
SaySay "Error opening source file "||source
Call Syntax
EndDo i = 1 By 1 Until Lines( source ) = 0
source.i = LineIn( source )
If case = 0 Then Do
source.i = translate( source.i, "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ" )
Endsource.0 = i
EndCall Stream source, "C", "CLOSE"
/* Remove duplicate lines */"CLS"Say "Searching "||source.0||" lines for duplicates . . ."
target. = ""
target.0 = 0
Do i = 1 By 1 To source.0
"CLS"Say "Searching "||source.0||" lines for duplicates . . ."
Say "Checking line "||i||" . . ."
duplicate = 0
If target.0 > 0 Then Do j = 1 By 1 To target.0
If source.i = target.j Then Do
duplicate = 1
Leave j End EndIf duplicate = 0 Then Do
k = target.0 + 1
target.k = source.i
target.0 = k EndEnd/* Release some memory */source. = ""
/* Save results */"CLS"Say "Saving results ("||target.0||" lines) . . ."
"DEL "||target||" >NUL 2>&1"
Do i = 1 By 1 To target.0
Call LineOut target, target.i
EndCall LineOut target
/* Done */Exit 0
Syntax: Procedure
SaySay "Unique.rex, Version 1.00 for Regina Rexx"
Say "Remove repeating lines from the specified text file"
SaySay "Usage: REGINA.EXE UNIQUE.REX sourcefile [ targetfile ] [ /I ]"
SaySay "Where: sourcefile is the file to be checked on repeated lines"
Say " targetfile is the file to which the result is written; the target file"
Say " is purged before the result is stored; if no target file is"
Say " specified, then the source file itself will be modified"
Say " /I case-insensitive comparisons; results will be all lowercase"
SaySay "Note: This Rexx script was written to check and modify small text files;"
Say " I also tested it with an 8000 line file with 5500 duplicate lines;"
Say " although it does work, with file sizes like that it is really slow!"
SaySay "Written by Rob van der Woude"
Say "http://www.robvanderwoude.com"
Exit 1
Returnpage last modified: 2025-10-11; loaded in 0.0071 seconds