0

我有两个 .properties 文件如下

    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

我想比较两个文件,需要从 first.properties 中删除通用名称-值对。输出文件应为

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

我使用了以下代码,但它给出了笛卡尔产品场景。你能帮我实现上述目标吗?

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
    )
    )
4

2 回答 2

1

要非常小心,充分解释你的任务。有了新信息,这在这里有效。

@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
)
于 2013-05-29T08:04:31.833 回答
0

尝试这个:

findstr /vg:second.properties first.properties>third.properties
于 2013-05-29T04:08:25.970 回答