ktraos
ktraos

Reputation: 127

How to remove common name=value pair from first file when compared with other file

I have two .properties files as follows

    first.properties                    second.properties
    -----------------                   ---------------------
    firstname=firstvalue                fourthname=fourthvalue
    secondname=secondvalue              sixthname=sixthvalue
    thirdname=thirdvalue                nineththname=ninethvalue
    fourthname=fourthvalue              tenthname=tenthvalue
    fifthname=fifthvalue
    sixthname=sixthvalue
    seventhname=seventhvalue

i want to compare two files and need to remove common name-value pair from first.properties. The output file should be as

    third.properties.
    ------------------ 
    firstname=firstvalue                
    secondname=secondvalue              
    thirdname=thirdvalue            
    fifthname=fifthvalue
    seventhname=seventhvalue

i used the following code,but it is giving Cartesian product scenario.can you please help me out to achieve the above.

for /F "tokens=1,2 delims==" %%E in (first.properties) do (
    for /F "tokens=1,2 delims==" %%G in (second.properties) do (
    if "%%E" NEQ "%%G" echo %%E=%%F>>!HOME!\Properties\third.properties
    )
    )

Upvotes: 0

Views: 73

Answers (2)

foxidrive
foxidrive

Reputation: 41224

Be very careful that you explain your task fully. With the new information, this works here.

@echo off
pushd "d:\folder"
copy /y "first.properties" "third.properties" >nul
for /f "delims==" %%a in (' type "second.properties" ') do (
find /v /i "%%a=" <"third.properties" > "third.properties.tmp"
move /y "third.properties.tmp" "third.properties" >nul
)

Upvotes: 1

Endoro
Endoro

Reputation: 37569

try this:

findstr /vg:second.properties first.properties>third.properties

Upvotes: 0

Related Questions