:: UNIQ.CMD
@Echo OFF
SetLocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
REM Clear all variables beginning with '$':
For /F "tokens=1* delims==" %%a in (
'"Set "$" 2>NUL:"') Do Set "%%a="
REM Define the variables from the list (here it is a file).
REM This will use the last occurrance of the line:
For /F "delims=" %%a in (%*) Do Set "$%%a=%%a"
REM Optionally use only the first occurrance of the line:
REM For /F "delims=" %%a in (%*) Do If NOT DEFINED $%%a Set "$%%a=%%a"
REM Print the unique list:
For /F "tokens=1* delims==" %%a in ('"Set "$" 2>NUL:"') Do Echo=!%%a!
Goto :EOF
This routine can be piped to SORT for a sorted list.
Frank
That's quite neat Frank. :-)
I have a couple of comments:
1) delayed expansion is not required or desirable
2) some lines containing = will cause a hiccough
3) I changed the command string below to a more conventional format - is
there a reason you used the format above?
4) the filesize might be a bit limited but I didn't test that.
:: UNIQ.CMD
@Echo OFF
REM Clear all variables beginning with '$':
For /F "tokens=1* delims==" %%a in ('Set $ 2^>NUL') Do Set "%%a="
REM read the file and set the variables
For /F "delims=" %%a in (%*) Do If NOT DEFINED $%%a Set "$%%a=%%a"
REM Print the unique list:
For /F "tokens=1* delims==" %%a in ('Set $ 2^>NUL') Do Echo=%%b
pause
REM Print the sorted unique list:
For /F "tokens=1* delims==" %%a in ('Set $ 2^>NUL^|sort') Do Echo=%%b
pause
--
Regards,
Mic
>>This routine can be piped to SORT for a sorted list.
>
>That's quite neat Frank. :-)
We failed to notice that SET $ sorts the list anyway.
> REM Print the unique list:
> For /F "tokens=1* delims==" %%a in ('Set $ 2^>NUL') Do Echo=%%b
--
Regards,
Mic
Like you, I noticed it shortly after I sent the message but I was
waiting for anoter excuse before sending a correction. You might have
noticed that I often send errors and very soon after I send corrections
to those errors. Sometimes my errors were not errors at all so my
corrections to those erroneous errors were themselves errors; then I
have to send another message correcting the erroneous correction. Words
and I are not friendly; they very often disagree with what I am saying.
"foxidrive" news:2mh2p511t8ktm9c4b...@4ax.com...
> I have a couple of comments:
> 1) delayed expansion is not required or desirable
Good correction.
> 2) some lines containing = will cause a hiccough
On mine it is a burp.
> 3) I changed the command string below to a more conventional format -
> is
> there a reason you used the format above?
I don't know what you are calling the "command string".
> 4) the filesize might be a bit limited but I didn't test that.
I considered that also. It was a simple routine and I did not try to
convey any idea that it would work in all cases. In CMD scripting it is
very often the case that routines need to be customized for the
application. When I work on a script I sometimes create routines that I
don't need so I don't spend any more time improving them, but they seem
too useful to allow them to be forgotten; so I send them here for others
to consider, use, and improve if necessary. It is nice that you thought
it worth improving. I think that with some work the hic-coughs and burps
can be removed also, making it complex; but it will be good as it is for
someone who knows that those deficiencies won't be a factor and in that
case the simple script is more desirable.
Frank