0

I have two text files: Last_RUN_Result.txt has:

AAAA
BBBB

The New_RUN_Result.txt has:

AAAA
CCCC

I need a Compare_Result.txt has:

AAAA

So I used the script as below:

        REM Search New_RUN_Result.txt's instance name in Last_RUN_Result.txt
rem         DEL Compare_Result.txt
        echo. 2>Compare_Result.txt
        for /F "tokens=1 delims= " %%j in (New_RUN_Result.txt) do (
            FIND /c "%%j" Last_RUN_Result.txt
            IF %ERRORLEVEL% EQU 0 (
                echo.%%j >> Compare_Result.txt
            ) 
        )

But I will get:

AAAA
CCCC

Could you please help me out of this? Thank you for your time:)

DBALUKE HUANG
  • 247
  • 1
  • 10
  • 2
    You should be able to do such a simple match with one single `FINDSTR` command. `FINDSTR /G:New_RUN_Result.txt Last_RUN_Result.txt` . And the problem with your code is that you are inside a parenthesized code block. You need to use delayed expansion if you want to use the variable !errorlevel!. Looking back at your previous questions, delayed expansion has been mentioned to you several times. If you still do not understand how it works please update your question. – Squashman Jun 20 '18 at 17:50
  • 1
    Possible duplicate of [Variables in batch not behaving as expected](https://stackoverflow.com/questions/30282784/variables-in-batch-not-behaving-as-expected) – Squashman Jun 20 '18 at 17:56
  • Thank you Squashman, It works! Much appreciated! – DBALUKE HUANG Jun 20 '18 at 19:20
  • 1
    Possible duplicate of [Errorlevel in a For loop (batch windows)](https://stackoverflow.com/questions/3942265/errorlevel-in-a-for-loop-batch-windows) – aschipfl Jun 20 '18 at 20:10

1 Answers1

0

Check out the fc command. Fc file1 file2 If you are looking for a way to easily separate new and old lines I could upload a tool called lc.exe which compares two files and puts lines unique to one file one in a doc old.txt and lines unique to the other in new.txt let me know if this still doesn’t answer your question or if you want the lc file. EDIT: Here is the LC.exe file https://1drv.ms/u/s!AlRLV33Rdz2CgrgfJLPN7GhkfV-KkA

Mark Deven
  • 550
  • 1
  • 9
  • 21