Hi,
I am not an expert in batch but i know you guys are experts so I come to you guys for help.
I am trying to manipulate a TXT file to catch a string and compare with other one but i was not able to do it.
I have the folow TXT:
"Executable version : 5.2.4.0
DLL version : 5.2.4.1
>>> Connecting to "database"
>>> Logging on to the database as "*****"
>>> Logon successful
>>> Beginning export..
Connection result:
ResultCode = 0x00000000
ResultDescription = A operação foi concluída com êxito.
Command result:
Command = ExportMachine
ResultCode = 0xdb000004
ResultDescription = O nome não foi encontrado no banco de dados"
I Need to compare the text marked in red with another similar string and check if the two marked in red are equal to the string comparison, both must be equals to the string comparison, and if the result is negative display an error message.
Someone please can help me with this? I'll be very grateful.
Reggards,
Rafael.
Read TXT file and compare strings
Moderator: DosItHelp
Re: Read TXT file and compare strings
Lets say the name of your text file is "xyz.txt" and it contains never more than two ResultCodes:
Regards
aGerman
Code: Select all
@echo off &setlocal
for /f "tokens=3" %%a in ('findstr /c:"ResultCode" "xyz.txt"') do (
if not defined ConnectionResultCode set "ConnectionResultCode=%%a"
if defined ConnectionResultCode set "CommandResultCode=%%a"
)
if "%ConnectionResultCode%"=="0x00000000" (
echo Connection Result Code is 0x00000000.
) else (
echo Connection Result Code is NOT 0x00000000.
)
if "%CommandResultCode%"=="0xdb000004" (
echo Command Result Code is 0xdb000004.
) else (
echo Command Result Code is NOT 0xdb000004.
)
pause
Regards
aGerman
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: Read TXT file and compare strings
download gawk for windows,
I am assuming you are comparing the 2 red colors against EACH OTHER. If not, show example of the string you are comparing the red colored code against.
Code: Select all
C:\test>gawk -F"[ \t]*=[ \t]*" "/^ResultCode/{a[++c]=$2}END{if (a[1]!=a[2]) print \"Not equal\"}" file
Not equal
I am assuming you are comparing the 2 red colors against EACH OTHER. If not, show example of the string you are comparing the red colored code against.
Re: Read TXT file and compare strings
Code: Select all
@echo off
set file=1.txt
set true=ResultCode = 0x00000000
for /f %%i in ('find /i /c "%true%" ^<"%file%"') do set cnt=%%i
if %cnt% neq 2 echo some errors occured