Compare text files and show only the errors

November 25, 2009 at 09:56:15
Specs: Windows XP
Hello experts,
i hv a problem now. Hope someone help me
I need to create a batch script that compare two text files (lets say test1.txt and test2.txt)

My text file look like
Test1.txt
Thu 11/26/2009 1:29:34.95
abc.txt.txt
abc2.txt.txt

and Test2.txt
Thu 11/26/2009 1:29:40.95
abc.txt.txt
abc3.txt.txt

The batch script should compare the lines in the text file first.
If the number of lines different in both text files, then its check the string inside the text file if its similar or not.
if its similar do nothing, or else its should write it in error.txt.

comparision should not include the first line (date)
Hope someone help me in this
thanks


See More: Compare text files and show only the errors

Report •


#1
November 25, 2009 at 10:14:27
Much depends on defining 'similsr'.


=====================================
Helping others achieve escape felicity

M2


Report •

#2
November 25, 2009 at 10:18:51
How to do that??
Sorry i hv no knowledge in batch script
learning now
Hope u can help me..

Report •

#3
November 25, 2009 at 11:17:46
Hope this helps

@echo off & cls & setlocal enabledelayedexpansion

REM // CREATE VARIABLES FOR FILE 1
set c1=0
for /f %%a in (Test1.txt) do (
set /a c1 +=1
set a!c1!=%%a
)
set finala=!c1!

REM // CREATE VARIABLES FOR FILE 2
set c2=0
for /f %%b in (Test2.txt) do (
set /a c2 +=1
set b!c2!=%%b
)

REM // TO CHECK WE COMPARE THE VARIABLES
set counter=1
:LOOP
if !a%counter%! == !b%counter%! (
REM echo Line %counter% = No change
if %counter% GEQ %finala% (goto :END)
set /a counter +=1
goto :LOOP
) else (
echo error... !a%counter%! and !b%counter%! on line %counter% don't match
if %counter% GEQ %finala% (goto :END)
set /a counter +=1
goto :LOOP
)

:END
echo Test complete.
pause>nul


Report •

Related Solutions

#4
November 25, 2009 at 11:20:27
Sorry, I didnt read that you dont want the first line compared! I will work more on this tomorrow unless someone else comes up with better code.
I cant go on now, gotta go paint!

Ciao


Report •

#5
November 25, 2009 at 11:34:06
just change this line:
set counter=1

to:
set /a counter=2


Report •

#6
November 25, 2009 at 14:59:38
Ha!!!! so simple!!! Thanks nbrane.

Report •


Ask Question