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
Related
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
Hi and thanks for answer, so my batch file that is intended to encrypt certain files with certain extensions. So there is my code:
#echo off
setlocal EnableDelayedExpansion
set "Alphabet=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
set "lowCase=abcdefghijklmnopqrstuvwxyz"
:a offset "input string" outVar=
setlocal DisableDelayedExpansion
set "inString=%~2"
set maxLen=80
set offset=11
set fname=%random%.%random%.%random%.%random%
setlocal EnableDelayedExpansion
(
for /f "tokens=*" %%X in ('dir /b /s *.encodeme') do (
FOR /f "delims=" %%a IN ('findstr /v /L /i /b /c:"INDEX?" "%%X"') DO (
SET "line=%%a"
call :A %offset% "!line!" a=
echo !a!
type %fname% > %%X
del /Q %fname%
)
)
)>"%fname%"
:A offset "input string" outVar=
setlocal DisableDelayedExpansion
set "inString=%~2"
setlocal EnableDelayedExpansion
for /L %%i in (0,1,61) do (
set /A "i=(%%i + %1) %% 62"
set c["!Alphabet:~%%i,1!"]=!i!
)
set "outVar="
for /L %%i in (0,1,%maxLen%) do (
set "char=!inString:~%%i,1!"
if defined char (
for /F "delims=" %%c in ("!char!") do (
if defined c["%%c"] (
set j=!c["%%c"]!
if "!lowCase:%%c=%%c!" neq "%lowCase%" set /A "j-=26"
for /F %%j in ("!j!") do set "outVar=!outVar!!Alphabet:~%%j,1!"
) else (
set "outVar=!outVar!!char!"
)
)
)
)
(
endlocal
for /F "delims=" %%a in ("%outVar:!=^!%") do endlocal & set "%3=%%a"
)
I have problem with the script that it will repeat its previous encrypted results.
For example, first encrypted file content is ok : Er6HGFJFrq6FJpFr6
Second example file content is repeated from previous on :
Er6HGFJFrq6FJpFr6
C:\Users\HP\Desktop\16383.29528.16703.12516
n6GJp6GJp7GF6
I want it to be just :
n6GJp6GJp7GF6
Sorry for my English, if you could help me, thank you!
Device1.bat
#echo off
:: script for updating property files
SETLOCAL EnableExtensions
SETLOCAL EnableDelayedExpansion
if "%3"=="" (
ECHO Script will optionally accept 3 args: PropKey PropVal File
SET PROPKEY=Deviceid
SET PROPVAL=dfs2341f
SET FILE=config.properties
) ELSE (
SET PROPKEY=%1
SET PROPVAL=%2
SET FILE=%3
)
FINDSTR /B %PROPKEY% %FILE% >nul
IF %ERRORLEVEL% EQU 1 GOTO nowork
MOVE /Y "%FILE%" "%FILE%.bak"
FOR /F "USEBACKQ tokens=*" %%A IN (`TYPE "%FILE%.bak" ^|FIND /N /I "%PROPKEY%"`) DO (
SET LINE=%%A
)
FOR /F "tokens=1,2* delims=]" %%S in ("%LINE%") DO SET LINE=%%S
SET /A LINE=%LINE:~1,6%
SET /A COUNT=1
FOR /F "USEBACKQ tokens=*" %%A IN (`FIND /V "" ^<"%FILE%.bak"`) DO (
IF "!COUNT!" NEQ "%LINE%" (
ECHO %%A>>"%FILE%"
) ELSE (
ECHO %PROPKEY%=%PROPVAL%>>"%FILE%"
ECHO Updated %FILE% with value %PROPKEY%=%PROPVAL%
)
SET /A COUNT+=1
)
GOTO end
:nowork
echo Didn't find matching string %PROPKEY% in %FILE%. No work to do.
pause
:end
Device2.bat
#echo off
:: script for updating property files
SETLOCAL EnableExtensions
SETLOCAL EnableDelayedExpansion
if "%3"=="" (
ECHO Script will optionally accept 3 args: PropKey PropVal File
SET PROPKEY=Deviceid
SET PROPVAL=dfs2341f
SET FILE=config.properties
) ELSE (
SET PROPKEY=%1
SET PROPVAL=%2
SET FILE=%3
)
FINDSTR /B %PROPKEY% %FILE% >nul
IF %ERRORLEVEL% EQU 1 GOTO nowork
MOVE /Y "%FILE%" "%FILE%.bak"
FOR /F "USEBACKQ tokens=*" %%A IN (`TYPE "%FILE%.bak" ^|FIND /N /I "%PROPKEY%"`) DO (
SET LINE=%%A
)
FOR /F "tokens=1,2* delims=]" %%S in ("%LINE%") DO SET LINE=%%S
SET /A LINE=%LINE:~1,6%
SET /A COUNT=1
FOR /F "USEBACKQ tokens=*" %%A IN (`FIND /V "" ^<"%FILE%.bak"`) DO (
IF "!COUNT!" NEQ "%LINE%" (
ECHO %%A>>"%FILE%"
) ELSE (
ECHO %PROPKEY%=%PROPVAL%>>"%FILE%"
ECHO Updated %FILE% with value %PROPKEY%=%PROPVAL%
)
SET /A COUNT+=1
)
GOTO end
:nowork
echo Didn't find matching string %PROPKEY% in %FILE%. No work to do.
pause
:end
I am running device1.bat and device2.bat at a time. Device1.bat is running properly.But device2.bat throwing The process cannot access the file because it is being used by another process.please help me to solve this problem.
You could make a temporary copy of the config.properties for the device2 to use and delete it later.
DEVICE 1:
#echo off
:: script for updating property files
SETLOCAL EnableExtensions
SETLOCAL EnableDelayedExpansion
if "%3"=="" (
ECHO Script will optionally accept 3 args: PropKey PropVal File
SET PROPKEY=Deviceid
SET PROPVAL=dfs2341f
SET FILE=config.properties
::make a temporary copy of config.properties
copy config.properties config2.properties
) ELSE (
SET PROPKEY=%1
SET PROPVAL=%2
SET FILE=%3
)
FINDSTR /B %PROPKEY% %FILE% >nul
IF %ERRORLEVEL% EQU 1 GOTO nowork
MOVE /Y "%FILE%" "%FILE%.bak"
FOR /F "USEBACKQ tokens=*" %%A IN (`TYPE "%FILE%.bak" ^|FIND /N /I "%PROPKEY%"`) DO (
SET LINE=%%A
)
FOR /F "tokens=1,2* delims=]" %%S in ("%LINE%") DO SET LINE=%%S
SET /A LINE=%LINE:~1,6%
SET /A COUNT=1
FOR /F "USEBACKQ tokens=*" %%A IN (`FIND /V "" ^<"%FILE%.bak"`) DO (
IF "!COUNT!" NEQ "%LINE%" (
ECHO %%A>>"%FILE%"
) ELSE (
ECHO %PROPKEY%=%PROPVAL%>>"%FILE%"
ECHO Updated %FILE% with value %PROPKEY%=%PROPVAL%
)
SET /A COUNT+=1
)
GOTO end
:nowork
echo Didn't find matching string %PROPKEY% in %FILE%. No work to do.
pause
:end
DEVICE2.bat:
#echo off
:: script for updating property files
SETLOCAL EnableExtensions
SETLOCAL EnableDelayedExpansion
if "%3"=="" (
ECHO Script will optionally accept 3 args: PropKey PropVal File
SET PROPKEY=Deviceid
SET PROPVAL=dfs2341f
::changed config.properties to config2.properties
SET FILE=config2.properties
) ELSE (
SET PROPKEY=%1
SET PROPVAL=%2
SET FILE=%3
)
FINDSTR /B %PROPKEY% %FILE% >nul
IF %ERRORLEVEL% EQU 1 GOTO nowork
MOVE /Y "%FILE%" "%FILE%.bak"
FOR /F "USEBACKQ tokens=*" %%A IN (`TYPE "%FILE%.bak" ^|FIND /N /I "%PROPKEY%"`) DO (
SET LINE=%%A
)
FOR /F "tokens=1,2* delims=]" %%S in ("%LINE%") DO SET LINE=%%S
SET /A LINE=%LINE:~1,6%
SET /A COUNT=1
FOR /F "USEBACKQ tokens=*" %%A IN (`FIND /V "" ^<"%FILE%.bak"`) DO (
IF "!COUNT!" NEQ "%LINE%" (
ECHO %%A>>"%FILE%"
) ELSE (
ECHO %PROPKEY%=%PROPVAL%>>"%FILE%"
ECHO Updated %FILE% with value %PROPKEY%=%PROPVAL%
)
SET /A COUNT+=1
)
GOTO end
:nowork
echo Didn't find matching string %PROPKEY% in %FILE%. No work to do.
pause
::delete the temporary config2.properties
del /f /q config2.properties
:end
hope that helps!
I have to make a script that has to calculate the mask and the net, so I'm trying a script with for but it can not convert the IP to binary. I think I'm not using the variables right.
Any ideas?
#echo off
setlocal enabledelayedexpansion
set var=%1
set /p var=Introduce la ip:
for /F "tokens=1 delims=." %%a in ("%var%") do (
echo %%a
set "vara=%%a"
:binario
set bin=2
set /a resto=%vara%%%bin%
set /a a=%vara%/%bin%
set resultado=%resto%%resultado%
if %vara% GTR 0 (goto binario)
echo %resultado%
goto siguiente
)
:siguiente
for /F "tokens=2 delims=." %%b in ("%var%") do (
echo %%b
)
for /F "tokens=3 delims=." %%c in ("%var%") do (
echo %%c
)
for /F "tokens=4 delims=." %%d in ("%var%") do (
echo %%d
)
goto fin
:vacio
echo Error!
goto fin
:fin
pause
You've got a few minor problems that I see. You set var=%1 but you never check to see whether %1 was supplied before doing set /p var=Enter an IP:. You never call or goto :vacio. As I commented above, modulos within batch scripts need to be written as %% to prevent evaluation as variable chararacters. You don't need % in var names in set /a commands, and you can combine multiple set /a statements with a comma. So instead of
set /a resto=%vara%%%bin%
set /a a=%vara%/%bin%
(which is wrong anyway -- I'll get to that in a minute), I suggest this would be more understandable and maintainable:
set /a resto = vara %% bin, numero = vara / bin
The biggest problem is that you appear to be trying to modify %%a. Don't do that.
If I were you, I would move the decimal to binary conversion to a subroutine, and call it for each octet. Try this:
#echo off
setlocal enabledelayedexpansion
set IP=%1
if "%IP%"=="" set /p "IP=Introduce la ip: "
set idx=0
for %%a in (%IP:.= %) do (
if %%a lss 0 goto vacio
if %%a gtr 255 goto vacio
if !idx! gtr 3 goto vacio
set /P "=%%a = "<NUL
call :dec2bin bin[!idx!] %%a
set /a idx += 1
)
echo %bin[0]%.%bin[1]%.%bin[2]%.%bin[3]%
goto fin
:dec2bin <var_para_definir> <numero>
setlocal enabledelayedexpansion
set numero=%~2
set bin=
for /L %%I in (1,1,8) do (
set /a bit = numero %% 2, numero /= 2
set bin=!bit!!bin!
)
echo %bin%
endlocal & set "%~1=%bin%"
goto :EOF
:vacio
echo Error!
goto fin
:fin
pause
For more information about using call as a function that returns a value, see this page.
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.