【发布时间】:2016-01-29 17:24:24
【问题描述】:
我正在尝试比较 IP 列表并使用 Windows 中的 findstr 命令输出差异,但我很难让它工作。我使用的命令是:
编辑:我的目标是将成功扫描的 IP 与成功扫描并实现身份验证的 IP 进行比较,并将其输出为不在 IPsSuccessfullyScannedwithAuthentication.txt 中但在 中的文件IPsSuccessfullyScanned.txt 到 IPsSuccessfullyScannedButNotAuthenticated.txt。
假设 IPsSuccessfullyScanned.txt 包含
192.168.0.1
192.168.0.2
192.168.0.3
192.168.0.4
192.168.0.5
192.168.0.6
192.168.0.7
192.168.0.8-192.168.0.12
和 IPsSuccessfullyScannedwithAuthentication.txt(经过身份验证并成功扫描的 IP)包含
192.168.0.1
192.168.0.2
192.168.0.3
192.168.0.4
192.168.0.6
192.168.0.8-192.168.0.10
192.168.0.12
我的 IPsSuccessfullyScannedButNotAuthenticated.txt 应该有这个:
192.168.0.5
192.168.0.7
192.168.0.11
findstr /vixg:IPsSuccessfullyScanned.txt IPsSuccessfullyScannedwithAuthentication.txt > IPsSuccessfullyScannedButNotAuthenticated.txt
我想要实现的与这篇文章非常相似:
.bat file to compare two text files and output the difference
这是我的问题,IPs2.txt 中的文件大小为 720 字节。 当我研究 findstr 命令时,我发现在进行正则表达式搜索时,最大搜索字符串长度为 254 字节。长度在 255 字节和 511 字节之间的正则表达式将导致 FINDSTR: Out of memory 错误,ERRORLEVEL 2。
正则表达式长度 >511 字节会导致 FINDSTR:搜索字符串太长。错误。 (这是我目前遇到的错误)。
我的问题是:我可以使用哪些替代方法来比较两个文本文件?如果有任何其他建议可以尽可能简单地解决我的问题,如果可能的话,即使是 bat 文件也可以提供帮助。
参考资料:
http://ss64.com/nt/findstr-escapes.html
What are the undocumented features and limitations of the Windows FINDSTR command?
【问题讨论】:
-
对不起,您的问题不清楚。你想要什么结果? IPs1.txt 中不存在的 IPs2.txt 中的行?反之亦然?两个都?另一个?
标签: windows shell batch-file scripting findstr