代码之家  ›  专栏  ›  技术社区  ›  Ahmed Abotaleb

“vbscript”查找行中有类似的单词,用冒号分隔“:”[关闭]

  •  -3
  • Ahmed Abotaleb  · 技术社区  · 7 年前

    我有一个包含5000多行的文本文件,每行有两个用冒号分隔的单词,例如(word1:word2) 我需要一个脚本来比较每一行上的(word1)和(word2),如果它们完全匹配,则将该行另存为一个新的文本文件。 提前感谢您的帮助

    1 回复  |  直到 7 年前
        1
  •  1
  •   Hackoo    7 年前

    只需将输入文件拖放到此批处理脚本上,您将得到一个新文件,其中包含相同的单词,并用冒号分隔:

    @echo off
    Mode 70,3 & color 0A
    Title Find lines have the similar words separated by a colon
    set "ScriptName=%~nx0"
    if "%~1"=="" goto error
    echo(
    echo      Find lines have the similar words separated by a colon
    Set "OutputFile=newfile.txt"
    If exist "%OutputFile%" Del "%OutputFile%"
    for /f "tokens=1,2 delims=:" %%a in ('Type %1') do (
        If [%%a]==[%%b] echo %%a:%%b
    )>>"%OutputFile%"
    Start "" "%OutputFile%" & Exit
    ::****************************************************************
    :Error
    Mode 70,5 & color 0C
    echo( & echo(
    echo      You should drag and drop your file over "%ScriptName%"
    Timeout /T 5 /nobreak>nul & exit
    ::****************************************************************