Solved batch to show unique value

January 30, 2013 at 06:45:55
Specs: window 2003

Hi scripting guru,

I have a text file, look like this:

http://www.abc.com
http://www.abc.com
http://www.abc.com/123.html
http://www.def.com
http://www.xyz.com
http://www.xyz.com

I would like to filter this text file using windows batch or vbs to show the unique value like this:

http://www.abc.com
http://www.abc.com/123.html
http://www.def.com
http://www.xyz.com

Thanks in advance !!


See More: batch to show unique value

Report •


#1
January 30, 2013 at 07:09:31

VBScript:
With CreateObject("Scripting.FileSystemObject")
  Set inFile = .OpenTextFile("test.txt")
  Set outFile = .OpenTextFile("out.txt", 2, True)
End With
Set dict = CreateObject("Scripting.Dictionary")

Do Until inFile.AtEndOfStream
  dict(Trim(inFile.ReadLine)) = True
Loop
For Each key In dict.Keys
  outFile.WriteLine key
Next 'key

How To Ask Questions The Smart Way


Report •

#2
January 30, 2013 at 07:36:51
✔ Best Answer

@echo off & setlocal EnableDelayedExpansion
set row=###
for /F "delims=" %%i in ('type "File.txt" ^| sort') do (
  if /I not "%%i"=="!row!" (echo.%%i >> "File.new" & set row=%%i)
)
ren "File.txt" "File.old"
ren "File.new" "File.txt"


Report •

#3
January 30, 2013 at 17:43:41

Magic!! It works~~

Thanks a million


Report •

Related Solutions


Ask Question