Batch - get content between two strings - windows

I have string like this
<AdaptationSet maxHeight="576" maxWidth="1024" mimeType="video/mp4" id="0" segmentAlignment="true" startWithSAP="1">
<ContentProtection schemeIdUri="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed" cenc:default_KID="bcf950eb-a062-5b0d-b1f2-fed53f20ba10">
<cenc:pssh>AAAATHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAACwiJGFlNWU5NTk4LWU5ODktNWM1Ny1iOTk2LTg3OTA4NWIyYzUxNUjj3JWbBg==</cenc:pssh>
</ContentProtection>
<ContentProtection schemeIdUri="urn:mpeg:dash:mp4protection:2011" value="cenc" cenc:default_KID="bcf950eb-a062-5b0d-b1f2-fed53f20ba10" />
<SegmentTemplate duration="6000" initialization="$RepresentationID$/video/init.mp4" media="$RepresentationID$_184201/segment_$Number$.m4s" startNumber="0" timescale="1000" />
<Representation bandwidth="247600" codecs="avc1.64001F" height="144" width="256" id="ae5e9598-e989-5c57-b996-879085b2c515-0_video_frag_auto.idx~video_frag_auto~481" scanType="progressive" />
I want to get output like below and put it into a variable.
ae5e9598-e989-5c57-b996-879085b2c515
Note that there is already id="0" in the first line and I want to extract value of id partially for the last line.
Is there an easy way to do this in batch?

If you must use batch, here's one example to get started. This extracts all values id from file ooo.txt that contains your string.
#echo off
setlocal enabledelayedexpansion
set x=0
for /f "eol=> tokens=* usebackq delims= " %%i in (`type ooo.txt`) do (
set x=0
set XXX=XXX
for %%I in (%%i) do (
if "%%I"=="id" (
set x=1
) else (
if !x! EQU 1 (
set x=0
set XXX=%%I
)
)
)
set XXX=!XXX:"=!
if not "!XXX!"=="XXX" (
set XXX=!XXX:"=!
rem echo !XXX!
call :enumerate !XXX! YYY
echo !YYY!
)
)
goto :eof
:enumerate
set pos=0
set Y=%1
set result=
set part=
:countchar
if not "!Y:~%pos%,1!"=="" (
set /a pos=pos+1
if "!Y:~%pos%,1!"=="-" (
set result=!result!!part!
set part=
)
set part=!part!!Y:~%pos%,1!
goto :countchar
)
set %~2=!result!
exit/b
:eof
endlocal
This outputs
ae5e9598-e989-5c57-b996-879085b2c515
and, within the loop, stores each id in variable YYY (although the first one is empty).
This assumes you want to keep everything up to but not including the last hyphen -.

Here's a 'for fun' example, which, as you've provided no code yourself, will not be modified post answer, and no support, or explanation, will be undertaken either.
#For /F Delims^= %%G In ('%__AppDir__%findstr.exe /i "id=\"[a-e0123456789]*-[a-e0123456789]*-[a-e0123456789]*-[a-e0123456789]*-[a-e0123456789]*-" "xmlfile.mpd"'
) Do #Set "}=%%G" & SetLocal EnableDelayedExpansion & For /F UseBackTokens^=2-6Delims^=-^" %%H In ('!}:* id^=^"^=!') Do #Endlocal & Set "id=%%H-%%I-%%J-%%K-%%L"
#(Set id) 2>NUL & Pause
You will probably want to change the source filename from xmlfile.mpd, and can optionally remove the last line, which was included just to allow you to see if it worked!

#ECHO OFF
SETLOCAL
rem The following settings for the source directory, destination directory, target directory,
rem batch directory, filenames, output filename and temporary filename [if shown] are names
rem that I use for testing and deliberately include names which include spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.
SET "sourcedir=u:\your files"
SET "filename1=%sourcedir%\q65892027.txt"
SET "capture="
SET "captured="
FOR /f "usebackqdelims=" %%b IN ("%filename1%") DO (
FOR %%c IN (%%b) DO (
IF /i "%%~c"=="scantype" SET "capture="&IF DEFINED captured GOTO done
IF DEFINED capture SET "captured=%%~c"
IF /i "%%~c"=="id" SET "capture=Y"
)
)
:done
ECHO captured "%captured%"
GOTO :EOF

setlocal enabledelayedexpansion
echo:
set "td=%~dp0"
set "pattern= id="
set "id=id"
call:getPatternLength "!id!" plen
set /a "slen=!plen!-1"
set "opt=tokens=1,2,* delims=<"
for /f "tokens=* delims=" %%z in (' type "!td!usedata\id.txt"^| findstr /c:"!pattern!" ') do (
for /f "%opt%" %%b in ("%%z") do (
for /f "tokens=* delims=" %%y in ('echo/%%b^|findstr /v [0-9][a-z]') do (
set "bempty=true"
call:findit "%%c" "!id!" strfound
)
if not defined bempty call:findit "%%b" "!id!" strfound
set "strfound=!strfound:"=!"
if defined strfound (
call:handlefound "!strfound!" result
if defined result (echo Finally: !result! & exit /b 0)
)
)
)
:end
endlocal
exit /b 0
:getPatternLength
set "str=%~1"
set /a "count=0"
:next
for /f "tokens=* delims=" %%z in ('echo/!str!') do (
set /a "count+=1"
set "str=!str:~1!"
if not "!str!"=="" goto:next
)
set "%2=!count!"
if /i "%0"==":getPatternLength" (exit /b 0)
:handlefound
set "str=%~1"
for /f "tokens=* delims=" %%a in ('echo/!str!^| findstr [a-z]') do (
:notyet
for /f "tokens=1,2,* delims=-" %%d in ("!str!") do (
for /f "tokens=* delims=" %%g in ('echo/%%e^|findstr "_"') do (
set "res=!res!-%%d"
set "%2=!res!"
exit /b 0
)
if not defined res ( set "res=%%d" ) else ( set "res=!res!-%%d")
set "str=%%e-%%f" & goto:notyet
)
)
echo Not the right line.. next.
exit /b 1
:findit
set "str=%~1"
set "find=%~2"
set "opts=tokens=1,* delims= "
set "opts2=tokens=1,* delims=="
:nexttoken
for /f "%opts%" %%m in ("!str!") do (
for /f "%opts2%" %%o in ("%%m") do (
if "%%o"=="!find!" (
set "%3=%%p"
if "%0"==":findit" exit /b 0
)
set "str=%%n" & goto:nexttoken
)
)
exit /b 1

Related

How to remove names from a list in batch

I'm using windows bath, I have a list of names that I can add to but I don't know how to remove a name from the list.
So far my code is:
#echo off
setlocal enabledelayedexpansion
set allchoices=123456789
set "names=Bob,Steven,Harry"
set amount=6 ::max limit of list
set list=0
:start
::echoes a list of all names in the list
for /l %%i in (1; 1; %amount%) do (
call :sub %%i
)
goto check
:sub
for /f "tokens=%1 delims=," %%a in ("%names%") do (
echo %%i. %%a
set /a list=list+1
)
goto :eof
:check
::Remove a name from the list
choice /c !allchoices:~0,%list%! /m "What name do you want to remove?"
if errorlevel 3 (
for /f "tokens=3 delims=," %%a in ("%names%") do (
echo you have choosen to remove %%a
::remove third name in the list
goto start
)
)
if errorlevel 2 ::remove second name in the list
if errorlevel 1 ::remove first name in the list
I've tried using del but that turns out to delete a file in your folder.
I've tried renaming a specific name using set name[%%a]="" but that did nothing.
Any ideas?
Have a look at this example. There are many ways.
#echo off
setlocal enabledelayedexpansion
set names="Bob","Steven","Harry"
for %%i in (%names%) do (
set /a num+=1
set "!num!=%%~i"
)
for /l %%a in (1,1,%num%) do (
set choices=!choices!%%a
echo !num!.!%%a!
)
choice /c 123 /m "please select name to remove"
for /l %%a in (1,1,%num%) do if not "!%%a!"=="!%errorlevel%!" set new_names=!new_names! !%%~a!
echo %new_names:~1%
It can be done without the last for loop as well.. but I opted for it.
Here is some example code, for you to run, and then try to comprehend, I hope it helps rather than confuses:
#Echo Off
SetLocal EnableDelayedExpansion
For /F "Delims==" %%A In ('Set # 2^>NUL') Do Set "%%A="
Set "i=0"
For /F "Delims=:" %%A In ('FindStr "^::" "%~f0" 2^>NUL') Do (
Set /A i+=1
Set "#!i!=%%A"
Echo= !i!. %%A
)
:Ask
Set # 1>NUL 2>&1
If ErrorLevel 1 Echo= Empty names list&Timeout 3 1>NUL&Exit /B
Echo=&Set /P "Option= Choose a name to remove>"
Set #|Findstr "^#%Option%=" 1>NUL||GoTo :Ask
Set "Name=!#%Option%!"
Echo= You've chosen to remove "%Name%"
Timeout 2 1>NUL
Set "#%Option%="
ClS
For /F "Tokens=1*Delims=#=" %%A In ('Set # 2^>NUL') Do Echo= %%A. %%B
GoTo Ask
::Alan
::Beth
::Cleo
::Dale
::Eric
::Faye
::Greg
::Hugh
::Inga
Important note:Please ensure, before saving the above content as a Windows Command Script, that there is a line return, (blank line), at the end.

How to create a unique output filename for Windows Script?

I am trying to create a windows script that should generate this kind of filename everytime I run it: filename1, filename2, filename3 and so on. Here is what I have so far:
(
#echo off
wmic logicaldisk get size,freespace,caption
) > disk.txt
I hope you can help me. Thanks!!
:: make a tempfile
:maketemp
SET "tempfile=%temp%\%random%"
IF EXIST "%tempfile%*" (GOTO maketemp) ELSE (ECHO.>"%tempfile%a")
You now have any number of filenames available.
%tempfile%a exists and is empty, but %tempfile%anythingelse should be available for use.
#ECHO OFF
SETLOCAL
SET "basename=filename"
SET /a outname=0
:genloop
SET /a outname+=1
IF EXIST "%basename% %outname%.txt" GOTO genloop
SET "outname=%basename% %outname%.txt"
ECHO %outname%
GOTO :EOF
Ah - increment the destination filename on each run. This should do that. It's not actually creating a file - you'd need to create the file %outname% each time to have it increment...
(the space between %basename% and %outname% is optional, of course - omit it if desired.)
edited to include .txt
This will give you up to 1000 filenames but you can go higher, up to 2 Billion, but the higher you go the longer the delay will be before it picks a filename.
#echo off
for /L %%a in (1,1,1000) do if not defined filename if not exist "filename%%a.txt" set "filename=filename%%a.txt"
(
wmic logicaldisk get size,freespace,caption
) > "%filename%"
#echo off
setlocal enableextensions
call :getNextFilename "filename*.txt" nextFilename
echo %nextFilename%
echo test > "%nextFilename%"
call :getNextFilename "%cd%\filename*.txt" nextFilename
echo %nextFilename%
echo test > "%nextFilename%"
endlocal
exit /b
:getNextFilename whatToSearch returnVariable
setlocal enableextensions enabledelayedexpansion
for /f %%a in ("$\%~1"
) do for /f "tokens=1,* delims=*" %%b in ("%%~nxa"
) do ( set "left=%%b" & set "right=%%c" )
set "max=0"
for %%a in ("%~1"
) do for /f "tokens=1 delims=%left%%right% " %%b in ("%%~nxa"
) do for /f "tokens=* delims=0 " %%c in ("0%%~b"
) do if %%~c geq !max! set /a "max=%%c+1"
endlocal & set "%~2=%~dp1%left%%max%%right%" & exit /b
This should find the next file in sequence independently of the existence of holes in the numeration of the files. A path can be included or omitted. The * will be used as the placeholder for the numeration. BUT this will not work if files or included paths have "problematic" characters.
If the date/time of creation of the file can be considered, then this version can be optimized as
:getNextFilename whatToSearch returnVariable
setlocal enableextensions disabledelayedexpansion
for /f %%a in ("$\%~1"
) do for /f "tokens=1,* delims=*?" %%b in ("%%~nxa"
) do ( set "left=%%b" & set "right=%%c" )
set "max=0"
for /f "delims=" %%a in ('dir /tc /o-d /b "%~1" 2^>nul'
) do for /f "tokens=1 delims=%left%%right% " %%b in ("%%~nxa"
) do for /f "tokens=* delims=0 " %%c in ("0%%~b"
) do set /a "max=%%c+1" & goto done
:done
endlocal & set "%~2=%~dp1%left%%max%%right%" & exit /b
that will take the latest created instance of the file set.
I finally figured out where to put the .txt extension. This is from #Magoo's answer but I wanted the file to be a text file so I placed the .txt twice in order for it to work properly.
#ECHO OFF
SETLOCAL
SET "basename=DISK-OUT"
SET /a outname=0
:genloop
SET /a outname+=1
IF EXIST "%basename% %outname%.txt" GOTO genloop
SET "outname=%basename% %outname%.txt"
(
wmic logicaldisk get size,freespace,caption
) > "%outname%"
GOTO :EOF

Read content of files and check if values are same

I have one file located at C:\Users\abc\Desktop named BUIBNESSDATE.
File contents are
Updated on :
Thu Jan 23 04:05:00 IST 2014
ProfileBusinessDate=23/1/2014
NucleusBusinessDate=23/01/2014
I want script which will check if both have same date(ProfileBusi nessDate & NucleusBusinessDate )date are same. If both date are same then script should give message as OK else NotOk.
how to do?
Test this:
#echo off
set "file=C:\Users\abc\Desktop\BUIBNESSDATE"
for /f "tokens=2 delims==" %%a in (' find /i "profile" ^< "%file%" ' ) do set "p=%%a"
for /f "tokens=2 delims==" %%a in (' find /i "nucleus" ^< "%file%" ' ) do set "n=%%a"
if "%p%"=="%n%" (echo OK) else (echo NotOK)
#ECHO OFF
SETLOCAL
SET "ppd="
SET "nbd="
FOR /f "delims=" %%a IN (q21312106.txt) DO (
SET "line=%%a"
CALL :process
)
IF NOT DEFINED ppd ECHO ProfileBusinessDate missing&GOTO :EOF
IF NOT DEFINED nbd ECHO NucleusBusinessDate missing&GOTO :EOF
FOR /f "tokens=1-3delims=/" %%a IN ("%ppd%") DO CALL :slz ppdd %%a&CALL :slz ppdm %%b&CALL :slz ppdy %%c
FOR /f "tokens=1-3delims=/" %%a IN ("%nbd%") DO CALL :slz nbdd %%a&CALL :slz nbdm %%b&CALL :slz nbdy %%c
IF "%ppdd%-%ppdm%-%ppdy%"=="%nbdd%-%nbdm%-%nbdy%" (ECHO OK) ELSE (ECHO NotOk)
GOTO :EOF
:process
SET "$1=%line:*ProfileBusinessDate=%"
IF NOT "%$1%"=="%line%" SET "ppd=%$1:~1%"&GOTO :EOF
SET "$1=%line:*NucleusBusinessDate=%"
IF NOT "%$1%"=="%line%" SET "nbd=%$1:~1%"&GOTO :EOF
GOTO :EOF
:: suppress a leading 0
:slz
SET "$1=%2"
IF "%$1:~0,1%"=="0" (SET "%1=%$1:~1%") ELSE (SET "%1=%2")
GOTO :eof
Should do the task. I used q21312106.txt with your data as a source file.
#echo off
setlocal enableextension disabledelayedexpansion
set "pdb="
set "nbd="
for /f "tokens=1,2 delims==" %%a in (
'findstr /b /l /c:"ProfileBusinessDate=" /c:"NucleusBusinessDate=" "c:\users\abc\desktop\buibnessdate"'
) do (
if "%%a"=="ProfileBusinessDate" (set "pbd=%%b" ) else (set "nbd=%%b")
)
if "%pdb%"=="%nbd%" (
echo OK
) else (
echo NOT OK
)
Search the file for the required lines, splitting them on equal sign and assigning the values to the adecuated variables. Then check if both variables hold the same content.

set nor working inside a for loop for windows dos cmd

I have a script that eill search for certain directories and set a list of paths for the given directories, now i want to exclude from them some recurrent unwanted ones.
Here's the script
#ECHO off
setlocal enableextensions
:start
set scriptname=%0%
set PAUSE_ON_ERROR=yes
rem #
rem ###### SECTION TO CUSTOMIZE #####
rem #
rem #
rem # This is the list of directories where instances of TECSYS iTopia installed under
rem # JBoss are located.
rem #
set jboss_dir_list=C: C:\TecsysDev\iTopiaControlPanel\trunk
rem #
rem ###### END SECTION TO CUSTOMIZE #####
rem #
set argNb=0
for %%x in (%*) do Set /A argNb+=1
if %argNb% GTR 1 (
goto :showUsage
) else if %argNb% == 0 (
set ENV_NAME=*
) else (
set ENV_NAME=*%~1*
)
:MainBlock
set scriptname=%0%
cd /d %~dp0
for /f "usebackq delims=" %%D in (`cd`) do set scriptdir=%%D
for /f "usebackq delims=" %%D in (`cd`) do set CURRENT_DIR=%%D
cd "%scriptdir%"
for /f "usebackq delims=" %%D in (`cd`) do set JBOSS_DIR=%%D
set JBOSS_DIR=%JBOSS_DIR%\..\..\..\..\..
cd "%JBOSS_DIR%"
for /f "usebackq delims=" %%D in (`cd`) do set JBOSS_DIR=%%D
cd "%CURRENT_DIR%"
rem Make sure that we have the findstr utility installed.
set findstr_found=
for /f "usebackq" %%f in (`echo x ^| findstr x 2^>nul`) do set findstr_found=%%f
if "X%findstr_found%" == "X" (
echo The findstr utility is not found.
goto pauseforError
)
call :getJbossVersion
rem prepare the list of special JBoss environments to exclude
if /i "%JBOSS_VERSION%" lss "5" (
set env_to_exclude=all default minimal
) else if /i "%JBOSS_VERSION%" lss "6" (
set env_to_exclude=all default minimal standard web
) else (
set env_to_exclude=all default minimal jbossweb-standalone standard
)
rem find the environment directories
setlocal enabledelayedexpansion
Set Count=1
for %%f in (%jboss_dir_list%) do (
for /f "delims=" %%G in ('dir /b /ad "%%~f\jboss*"') do (
if exist "%%f\%%G\server\%ENV_NAME%" (
for /f "delims=" %%H in ('dir /b /ad "%%~f\%%~G\server\%ENV_NAME%"') do (
echo count est !count!
call :concat %%~f\%%~G\server\%%~H
Set /A Count+=1
)
)
)
)
rem echo %ENV_NAME%
rem %jboss_home_list%
:concat
echo the environment is %1
set is_env_to_exclude=no
for %%L in (%env_to_exclude%) do (
set is_env_to_exclude=no
for /f "usebackq delims=" %%U in (`echo %1 ^| findstr %%L`) do (
set is_env_to_exclude=yes
echo flag du Ellouze
)
)
echo %is_env_to_exclude%
rem echo %is_env_to_exclude%
rem set jboss_home_list=%1 %jboss_home_list%
goto :eof
:getJbossVersion
for /f "usebackq tokens=2" %%v in (`echo. ^| %JBOSS_DIR%\bin\run.bat -V ^| ^
findstr "JBoss" ^| findstr /i /v "BootStrap"`) do (
set JBOSS_VERSION=%%v
)
goto :EOF
:showUsage
echo Usage: tish [environment]
echo ^|
echo +--- installed environment
rem SET /P uname=Please enter your name:
rem IF "%uname%"=="" GOTO Error
rem ECHO Hello %uname%, Welcome to DOS inputs!
rem GOTO End
rem :Error
rem ECHO You did not enter your name! Bye bye!!
:pauseforError
if "%PAUSE_ON_ERROR%" == "yes" pause
:End
My idea is to to do the filetring through the :concat subroutine, problem is set is_env_to_exclude=yes insrtuction inside the for loop isn't working, when i execute the script the echo flag is displaying but the set is_env_to_exclude is always set to no.
I think what you need is to break the loop:
echo the environment is %1
set is_env_to_exclude=no
for %%L in (%env_to_exclude%) do (
set is_env_to_exclude=no
for /f "usebackq delims=" %%U in (`echo %1 ^| findstr %%L`) do (
set is_env_to_exclude=yes
echo flag du Ellouze
goto :break_loop
)
)
:break_loop
echo %is_env_to_exclude%
as on each iteration over %env_to_exclude% items the is_env_to_exclude is set to no.
Although the code is a little bit complicated for me :)
It really depends on the contents of env_to_exclude.
is_env_to_exclude will be set to no for each %%L, so even if it is set to yes once, if there are more elements processed after it's been set, it will be re-set to no.
The
set is_env_to_exclude=no
in the loop seems to be the culprit; removing it would seem to fix the problem.
AAMOI, set "flag=" and set flag=Y allows if [not] defined flag which has the added advantage that the CURRENT status of the flag is available within a FOR loop without needing enabledelayedexpansion.

Batch file needed for comparing two files

This is my requirement in windows batch file I tried the following
Example:
f1.txt
sam
varun
ramesh
babu
f2.txt
babu
sam
I need the output of
varun
ramesh
The program
#echo on
SETLOCAL EnableDelayedExpansion
for /F "tokens=* delims=." %%a in (f1.txt) do (
call :myInnerLoop "%%a"
)
echo out of inner loop
)
goto :eof
:myInnerLoop
for /F "tokens=* delims=." %%b in (f2.txt) do (
if "%~1"=="%%b" (
echo inside inner loop
goto :next
) else (
echo %%a >> "E:\test\diff.txt"
)
:next
goto :eof
But it is not working kindly help me.
Even I tried diff utility also from http://gnuwin32.sourceforge.net/packages/diffutils.htm no help.
Your code is almost correct, but you have some () wrong. Try this one:
#echo off
del d:\test\windows\comp\diff.txt
SETLOCAL EnableDelayedExpansion
for /F "tokens=* delims=." %%a in (f1.txt) do (
echo %%a
call :myInnerLoop "%%a"
)
echo out of inner loop
goto :eof
:myInnerLoop
for /F "tokens=* delims=." %%b in (f2.txt) do (
echo "x: " %~1
echo "y: " %%b
if "%~1"=="%%b" (
echo next
goto :next
)
)
echo "Log " %~1
echo %~1 >> "d:\test\windows\comp\diff.txt"
:next
goto :eof
Are you looking for the comp command?
Compares the contents of two files or sets of files.
COMP [data1] [data2] [/D] [/A] [/L] [/N=number] [/C] [/OFF[LINE]]
data1 Specifies location and name(s) of first file(s) to compare.
data2 Specifies location and name(s) of second files to compare.
/D Displays differences in decimal format.
/A Displays differences in ASCII characters.
/L Displays line numbers for differences.
/N=number Compares only the first specified number of lines in each file.
/C Disregards case of ASCII letters when comparing files.
/OFF[LINE] Do not skip files with offline attribute set.
To compare sets of files, use wildcards in data1 and data2 parameters.
The best way to compare files in both directions
#echo off
::*********-Code by S-S Guca Srbija 2019-*********
title File-Compare by s-s
mode con cols=41 lines=10 & color 09
Set "File1a=File1.txt"
Set "File2b=File2.txt"
Set "Result=CompareResult.txt"
::************************************************
Set "File1b=%File1a%"
Set "File2a=%File2b%"
:Start
cls
set "Write=0"
Set /a "Test1+=1"
Echo(
Echo(=========================================
Echo( I compare Files %File1a% To %File2b%
Echo(=========================================
FOR /F "delims=" %%A in (%File1a%) do (
Set /a "LineNum1+=1"
Call :EXloop "%%A"
)
IF "%Test1%"=="2" Goto:End
Set "File1a=%File2a%"
Set "File2b=%File1b%"
Set "LineNum1="
Set "LineNum2="
Goto:Start
:End
EXIT
:EXloop
FOR /F "delims=" %%B in (%File2b%) do (
IF "%~1"=="%%B" goto:next
)
Set "LineNum2=0"
FOR /F "delims=" %%C in (%File2b%) do (
Set "MyFiles=%%C"
Call :LineCount
)
Goto:next1
:LineCount
Set /a "LineNum2+=1"
IF "%LineNum2%"=="%LineNum1%" (
set "File2=%MyFiles%"
)
goto:eof
:next1
Echo(>> "%Result%"
IF "%Test1%"=="1" (
set /a "Write+=1"
IF "%Write%"=="0" (
Echo( They were compared %File1a% To %File2b%>> "%Result%"
)
)
IF "%Test1%"=="2" (
set /a "Write+=1"
IF "%Write%"=="0" (
Echo( They were compared %File1a% To %File2b%>> "%Result%"
)
)
Echo(>> "%Result%"
Echo(=========================>> "%Result%"
Echo(%File1a%=Line=%LineNum1%=%~1>> "%Result%"
Echo((------------------------)>> "%Result%"
Echo(%File2b%=Line=%LineNum1%=%File2%>> "%Result%"
Echo(=========================>> "%Result%"
:next
goto:eof
::*********-Code by S-S Guca Srbija 2019-*********
OR
#echo off
::*********-Code by S-S Guca Srbija 2019-*********
title File-Compare by s-s
mode con cols=41 lines=10 & color 09
SETLOCAL EnableDelayedExpansion
Set "File1a=File1.txt"
Set "File2b=File2.txt"
Set "Result=CompareResult.txt"
::************************************************
Set "File1b=!File1a!"
Set "File2a=!File2b!"
:Start
cls
set "Write=0"
Set /a "Test1+=1"
Echo(
Echo(=========================================
Echo( I compare Files !File1a! To !File2b!
Echo(=========================================
FOR /F "delims=" %%A in (!File1a!) do (
Set /a "LineNum1+=1"
Call :EXloop "%%A"
)
IF "%Test1%"=="2" Goto:End
Set "File1a=!File2a!"
Set "File2b=!File1b!"
Set "LineNum1="
Set "LineNum2="
Goto:Start
:End
SETLOCAL DisableDelayedExpansion
EXIT
:EXloop
FOR /F "delims=" %%B in (!File2b!) do (
IF "%~1"=="%%B" goto:next
)
Set "LineNum2=0"
FOR /F "delims=" %%C in (!File2b!) do (
Set "MyFiles=%%C"
Call :LineCount
)
Goto:next1
:LineCount
Set /a "LineNum2+=1"
IF "%LineNum2%"=="%LineNum1%" (
set "File2=!MyFiles!"
)
goto:eof
:next1
Echo(>> "!Result!"
IF "%Test1%"=="1" (
set /a "Write+=1"
IF "%Write%"=="0" (
Echo( They were compared !File1a! To !File2b!>> "!Result!"
)
)
IF "%Test1%"=="2" (
set /a "Write+=1"
IF "%Write%"=="0" (
Echo( They were compared !File1a! To !File2b!>> "!Result!"
)
)
Echo(>> "!Result!"
Echo(=========================>> "!Result!"
Echo(!File1a!=Line=!LineNum1!=%~1>> "!Result!"
Echo((------------------------)>> "!Result!"
Echo(!File2b!=Line=!LineNum1!=!File2!>> "!Result!"
Echo(=========================>> "!Result!"
:next
goto:eof
::*********-Code by S-S Guca Srbija 2019-*********
:: Modify the code as you needed

Resources