用批处理或vbs删除文本行中出现两次及以上的字符

来源:百度知道 编辑:UC知道 时间:2024/06/08 10:46:17
只保留出现一次的行,凡出现两次及以上的都删除。以如下文本为例,处理后的结果只剩下了一行:yushi假装

herxunzi
yushi假装
herxunzi
bmw810318
河流008
bmw810318
河流008
河流008

批处理!

@echo off & setlocal Enabledelayedexpansion
mode con: cols=53 lines=10&color 0e
if exist "结果.txt" del /q /f /a "结果.txt"
set /p file=请把你要处理的文本文件拖到本窗口或手动输入路径文件名:
set "file=!file:"=!"
@for /f "delims=" %%i in ('type "%file%"') do (
set /a n=0
@for /f "delims=" %%b in ('type "%file%"^|find /i "%%i"') do set /a n+=1
if !n!==1 echo %%i>>结果.txt
)
exit

假如你的文本是a.txt,试运行以下批处理。
@echo off
for /f "delims=" %%a in ('type a.txt')do (
for /f "tokens=3 delims=: " %%b in ('find /c "%%a" a.txt')do (
if %%b==1 echo/%%a>>ok.txt))
start ok.txt