Search code examples
batch-filevbscriptcomparesimilaritydifference

"vbscript" find lines have the similar words separated by the colon " : "


I have a text file contains more than 5000 lines, each line has two words separated by colon eg( word1:word2 ) I need a script compares the (word1) with (word2) on each line if they exactly matched it saves the line as it in a new text file. Thank you in advance for your help


Solution

  • Just drag and drop your input file over this batch script and you will get a new file with the same word separated by a colon :

    @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
    ::****************************************************************