最近需要將重復(fù)的內(nèi)容去掉,所以就想到了使用bat或vbs實現(xiàn),沒想到網(wǎng)上已經(jīng)有人寫好了,測試也正好學(xué)習(xí)一下
@echo off
:: Code by oicu#lsxk.org 2007/11/29
rem chcp 437>nul
:: 看情況使用,utf-8編碼的文件不能少了chcp命令,一般無需使用,
:: 但無論是否使用都不支持utf-16的文件。
:: pushd "%~dp1"
:: 如果不用pushd和popd,文件都要用絕對路徑不能只用文件名。
if "%~1"=="" goto :EOF
set outputfile=%~dpn1_output%~x1
type nul>"%outputfile%"
echo Waiting...
for /F "tokens=1* delims=:" %%i in ('findstr /n .* "%~1"') do (
findstr /B /E /C:"%%j" "%outputfile%">nul 2>1 || echo.%%j>>"%outputfile%"
)
pause
start "" notepad "%outputfile%"
:: popd
exit
以下是這個腳本的源代碼,復(fù)制后另存為vbs后綴的文件,雙擊即可運(yùn)行。文件要放在C盤根下的Text.TXT,請?zhí)貏e注意:文本中一行一條記錄,不要有空行。
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = H0001
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
strPathToTextFile = "C:\"
strFile = "Test.txt"
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
"Data Source=" strPathtoTextFile ";" _
"Extended Properties=""text;HDR=NO;FMT=Delimited"""
objRecordSet.Open "Select DISTINCT * FROM " strFile, _
objConnection, adOpenStatic, adLockOptimistic, adCmdText
Do Until objRecordSet.EOF
Set objFSO = CreateObject("Scripting.FileSystemObject")
set Fp=objFSO.OpenTextFile("C:\test1.txt",8,True,0)
fp.WriteLine objRecordSet.Fields.Item(0).Value
fp.close
set objFSO = nothing
objRecordSet.MoveNext
Loop