Batch processing text file to repeat implementation code _dos/bat

Source: Internet
Author: User
Tags processing text

Recently need to remove the duplicate content, so I thought of using bat or VBS implementation, did not expect to have been written on the internet, testing is just learning

How to: Drag the text onto the batch process ...

@echo
off:: Code by oicu#lsxk.org 2007/11/29

rem chcp 437>nul
:: See Use, UTF-8 encoded files can not be less chcp command, generally no use, :
: But utf-16 files are not supported regardless of whether they are in use or not. ::

pushd "%~dp1"
:: If you do not use pushd and popd, the file must use absolute path not only file names.

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& gt;&1 | | Echo.%%j>> "%outputfile%"
)

pause
Start "" Notepad "%outputfile%":
: popd
exit

"In Oicu (oh! I-you!) The masterpiece said: "
: It's OK to repeat. The disadvantage is to slow and keep the original blank line.

The following is the code for the VBS implementation

The following is the source code for this script, copied after the file saved as a VBS suffix, double-click to run. Files to be placed in the C-packing Text.TXT, please pay special attention to: a line of text in a record, do not have blank lines.

Const ADOPENSTATIC = 3
Const ADLOCKOPTIMISTIC = 3
Const adCmdText = &h0001 
Set objconnection = Createobjec T ("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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.