中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟
中国DOS联盟论坛
现在时间是 2026-08-12 04:33
47,811 主题排行 / 349,897 发帖 / 今日 0 篇 / 48,256 会员排行
DOS批处理 & 脚本技术(批处理室) » [已结]文件内容比对
可打印版本  3,055 / 21
第1楼 coldface 发表于 2010-09-02 14:35
初级用户 发帖 70 积分 71
[已结]文件内容比对
请教个问题,比如A文件的内容是:

MinimumPasswordAge = 0
MaximumPasswordAge = 42

AuditSystemEvents = 3
AuditLogonEvents = 3
AuditObjectAccess = 2
AuditPrivilegeUse = 2
AuditPolicyChange = 3
AuditAccountManage = 3
B文件的内容是:

MinimumPasswordAge = 0
LSAAnonymousNameLookup = 0
EnableAdminAccount = 1
EnableGuestAccount = 0

AuditPolicyChange = 3
AuditAccountManage = 3
如果把A文件中的内容作为标准内容,在B中查找那些与A相同项目的后面赋值,如果不一样则提示总的不符的个数以及哪些内容一致。
批处理如何实现,谢谢!

[ Last edited by coldface on 2010-9-12 at 15:41 ]
第2楼 coldface 发表于 2010-09-02 14:49
初级用户 发帖 70 积分 71
补充下,我的文件里内容很多,而且比较长,
FC的话是没法的,试过了。
内容具体如下:

[Unicode]
Unicode=yes
[System Access]
MinimumPasswordAge = 0
MaximumPasswordAge = 42
MinimumPasswordLength = 0
PasswordComplexity = 0
PasswordHistorySize = 0
LockoutBadCount = 0
ResetLockoutCount = 0
LockoutDuration = 0
RequireLogonToChangePassword = 0
ForceLogoffWhenHourExpire = 0
ClearTextPassword = 0
LSAAnonymousNameLookup = 0
EnableAdminAccount = 1
EnableGuestAccount = 0
[Event Audit]
AuditSystemEvents = 3
AuditLogonEvents = 3
AuditObjectAccess = 2
AuditPrivilegeUse = 2
AuditPolicyChange = 3
AuditAccountManage = 3
AuditProcessTracking = 0
AuditDSAccess = 2
AuditAccountLogon = 3
[Registry Values]
MACHINE\Software\Microsoft\Driver Signing\Policy=3,1
MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Setup\RecoveryConsole\SecurityLevel=4,0
MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Setup\RecoveryConsole\SetCommand=4,0
MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\AllocateCDRoms=1,"0"
MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\AllocateDASD=1,"0"
MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\AllocateFloppies=1,"0"
MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\CachedLogonsCount=1,"10"
MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\ForceUnlockLogon=4,0
MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\PasswordExpiryWarning=4,14
MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\ScRemoveOption=1,"0"
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableCAD=4,1
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\DontDisplayLastUserName=4,1
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\LegalNoticeText=7,
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ScForceOption=4,0
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ShutdownWithoutLogon=4,0
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\UndockWithoutLogon=4,1
MACHINE\Software\Policies\Microsoft\Windows\Safer\CodeIdentifiers\AuthenticodeEnabled=4,0
MACHINE\System\CurrentControlSet\Control\Lsa\AuditBaseObjects=4,0
MACHINE\System\CurrentControlSet\Control\Lsa\CrashOnAuditFail=4,0
MACHINE\System\CurrentControlSet\Control\Lsa\DisableDomainCreds=4,1
MACHINE\System\CurrentControlSet\Control\Lsa\EveryoneIncludesAnonymous=4,0
MACHINE\System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy=4,0
MACHINE\System\CurrentControlSet\Control\Lsa\ForceGuest=4,0
MACHINE\System\CurrentControlSet\Control\Lsa\FullPrivilegeAuditing=3,0
MACHINE\System\CurrentControlSet\Control\Lsa\LimitBlankPasswordUse=4,1
MACHINE\System\CurrentControlSet\Control\Lsa\LmCompatibilityLevel=4,2
MACHINE\System\CurrentControlSet\Control\Lsa\MSV1_0\NTLMMinClientSec=4,0
MACHINE\System\CurrentControlSet\Control\Lsa\MSV1_0\NTLMMinServerSec=4,0
MACHINE\System\CurrentControlSet\Control\Lsa\NoDefaultAdminOwner=4,0
MACHINE\System\CurrentControlSet\Control\Lsa\NoLMHash=4,1
MACHINE\System\CurrentControlSet\Control\Lsa\RestrictAnonymous=4,1
MACHINE\System\CurrentControlSet\Control\Lsa\RestrictAnonymousSAM=4,1
MACHINE\System\CurrentControlSet\Control\Print\Providers\LanMan Print Services\Servers\AddPrinterDrivers=4,1
MACHINE\System\CurrentControlSet\Control\SecurePipeServers\Winreg\AllowedExactPaths\Machine=7,
MACHINE\System\CurrentControlSet\Control\SecurePipeServers\Winreg\AllowedPaths\Machine=7,
MACHINE\System\CurrentControlSet\Control\Session Manager\Kernel\ObCaseInsensitive=4,1
MACHINE\System\CurrentControlSet\Control\Session Manager\Memory Management\ClearPageFileAtShutdown=4,0
MACHINE\System\CurrentControlSet\Control\Session Manager\ProtectionMode=4,1
MACHINE\System\CurrentControlSet\Control\Session Manager\SubSystems\optional=7,Posix
MACHINE\System\CurrentControlSet\Services\LanManServer\Parameters\NullSessionPipes=7,
MACHINE\System\CurrentControlSet\Services\LanManServer\Parameters\NullSessionShares=7,
MACHINE\System\CurrentControlSet\Services\LanmanWorkstation\Parameters\EnablePlainTextPassword=4,0
MACHINE\System\CurrentControlSet\Services\LanmanWorkstation\Parameters\EnableSecuritySignature=4,1
MACHINE\System\CurrentControlSet\Services\LanmanWorkstation\Parameters\RequireSecuritySignature=4,0
MACHINE\System\CurrentControlSet\Services\LDAP\LDAPClientIntegrity=4,1
MACHINE\System\CurrentControlSet\Services\Netlogon\Parameters\DisablePasswordChange=4,0
MACHINE\System\CurrentControlSet\Services\Netlogon\Parameters\MaximumPasswordAge=4,30
MACHINE\System\CurrentControlSet\Services\Netlogon\Parameters\RequireSignOrSeal=4,1
MACHINE\System\CurrentControlSet\Services\Netlogon\Parameters\RequireStrongKey=4,0
MACHINE\System\CurrentControlSet\Services\Netlogon\Parameters\SealSecureChannel=4,1
MACHINE\System\CurrentControlSet\Services\Netlogon\Parameters\SignSecureChannel=4,1
[Version]
signature="$CHICAGO$"
Revision=1
第3楼 coldface 发表于 2010-09-07 10:16
初级用户 发帖 70 积分 71
这个还没想到方法,谁帮助下
第4楼 ZJHJ 发表于 2010-09-07 11:48
高级用户 发帖 374 积分 609
把你的真实文件上传
第5楼 coldface 发表于 2010-09-07 12:53
初级用户 发帖 70 积分 71
上面那个就是文件里的原始内容了
第6楼 slore 发表于 2010-09-07 13:24
铂金会员 发帖 2,478 积分 5,212
for一遍全set 前导字符%%i

再for另一个文件 delims==
if %%j==!前导字符%%i! ... else ...
第7楼 coldface 发表于 2010-09-07 14:11
初级用户 发帖 70 积分 71
延伸下,首先比对=前面的字符串,如果一样则比对=后面的数值是否一致。
如果=前面的字符串不一样则把B的此行写入一个文件C。

按照slore的提示,我写前面的字符串比对:

@echo off&setlocal ENABLEDELAYEDEXPANSION
for /f %%i in (A.txt) do (
set str=%%i
for /f "tokens=1 delims==" %%k in (B.txt) do (
if "%%k"=="!str:~1!" echo "It is the same" else echo %%k
)
)
但是运行没结果,说明在字符串比较方面有问题啊?

[ Last edited by coldface on 2010-9-7 at 14:54 ]
第8楼 slore 发表于 2010-09-07 16:48
铂金会员 发帖 2,478 积分 5,212
两个循环不是嵌套的。。。是顺序的。
第9楼 coldface 发表于 2010-09-07 17:47
初级用户 发帖 70 积分 71
那这个不知道怎么写了
@echo off&setlocal ENABLEDELAYEDEXPANSION
for /f %%i in (3.txt) do set str1=%%i
for /f "tokens=1* delims==" %%k in (4.txt) do
(
if "%%k"=="!str1!"....
第10楼 coldface 发表于 2010-09-07 20:58
初级用户 发帖 70 积分 71
帮忙下
谢谢
第11楼 slore 发表于 2010-09-07 22:57
铂金会员 发帖 2,478 积分 5,212
@echo off&setlocal ENABLEDELAYEDEXPANSION
for /f "eol=[ delims=" %%i in (1.txt) do set "OLD_%%i"
for /f "eol=[ tokens=1,2 delims==" %%i in (2.txt) do (
if "!OLD_%%i!"=="" (
echo %%i 为新属性
) else (
if not "%%j"=="!OLD_%%i!" (
echo %%i=%%j 不同与 !OLD_%%i!
)
)
)
pause


大致如这般,你自己看着改吧。
第12楼 slore 发表于 2010-09-07 22:58
铂金会员 发帖 2,478 积分 5,212
建议用比较专业的比较工具,比如Beyond Compare什么的,带命令行也是很方便很强大的
第13楼 coldface 发表于 2010-09-08 11:44
初级用户 发帖 70 积分 71
恩 ,谢谢,你那段如果是检查短的字符的话没有问题。
但是文件里包含一些比较长的内容:

[Registry Values]
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableCAD=4,1
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\DontDisplayLastUserName=4,1
MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\LegalNoticeText=7,1
这样的话就无法比较了。
关于用BC或者UC,这些关键对平台有一定的依赖性,不能很好的做“移植”,其实我做这个的初衷是对每台主机的本地安全策略与标准的安全策略做比较的
第14楼 slore 发表于 2010-09-08 12:00
铂金会员 发帖 2,478 积分 5,212
长的可以。。。

我估计是你文件太长了?CMD变量可能有个数限制。。

你复制你上面13L的内容保存为1.txt
复制一份为2.txt
然后随便改下值。。。

你运行BC12.BAT你看下结果。
第15楼 coldface 发表于 2010-09-08 14:04
初级用户 发帖 70 积分 71
恭喜你答对,是我文件太长,我那会是截取了一部分做的比对。
变量个数的最多数量可以修改么?
1 2  下一页
[ 联系联盟系统管理团队 - 中国DOS联盟 - 标准版 ]
Sponsored by ifanr Inc | © 2001–2023