Windows 用于删除重复行但希望忽略/跳过某些行的批处理脚本
在从xml文件中删除其他重复项时,是否也可以忽略一些重复行,例如:如果my abx.xml是 代码: 请仅使用批处理脚本Windows 用于删除重复行但希望忽略/跳过某些行的批处理脚本,windows,batch-file,duplicates,file-processing,Windows,Batch File,Duplicates,File Processing,在从xml文件中删除其他重复项时,是否也可以忽略一些重复行,例如:如果my abx.xml是 代码: 请仅使用批处理脚本 <bookstores> <book id="parent"> <name="it1"/> <name="it1"/> <name="it2"/> </book> <book id="child"> <name="it1"
<bookstores>
<book id="parent">
<name="it1"/>
<name="it1"/>
<name="it2"/>
</book>
<book id="child">
<name="it1"/>
<name="it1"/>
<name="it2"/>
<name="it3"/>
</book>
</bookstores>
输出应为:
<bookstores>
<book id="parent">
<name="it1"/>
<name="it2"/>
</book>
<book id="child">
<name="it3"/>
</book>
</bookstores>
但我得到的结果是:
注意:
标记已删除
<bookstores>
<book id="parent">
<name="it1"/>
<name="it2"/>
</book>
<book id="child">
<name="it3"/>
</bookstores>
我已经搜索了几个类似的请求,但大多数都在删除所有重复的行,但不确定如何忽略一些重复的行:
如果您在
%dict%
文件中放置要始终打印的行,这可能对您有用:
@ECHO OFF &SETLOCAL ENABLEDELAYEDEXPANSION
SET "file=file"
SET "new=new"
SET "dict=dictionary"
(FOR /f "tokens=1*delims=:" %%a IN ('findstr /n "^" "%file%"') DO (
SET "nr=%%a"
SET "line=%%b"
SET "this="
FINDSTR /l "!line!" "%dict%" >NUL 2>&1&& ECHO(!line! || (
FOR /f "tokens=1*delims==" %%x IN ('set "$" 2^>nul') DO IF !line!==%%y SET "this=1"
IF "!this!"=="" (
ECHO(!line!
SET "$!nr!=!line!"
)
)
))>"%new%"
TYPE "%new%"
…shell会议:
>type file
<bookstores>
<book id="parent">
<name="it1"/>
<name="it1"/>
<name="it2"/>
</book>
<book id="child">
<name="it1"/>
<name="it1"/>
<name="it2"/>
<name="it3"/>
</book>
</bookstores>
>type dictionary
</book>
>script.bat
<bookstores>
<book id="parent">
<name="it1"/>
<name="it2"/>
</book>
<book id="child">
<name="it3"/>
</book>
</bookstores>
>类型文件
>类型词典
>script.bat
您试图将XML视为纯文本文件。是的,不是的。XML是一种结构,您发布的链接是针对非结构化文件的。有时你必须使用正确的工具来完成这项工作。类似的东西更适合于此。发布您的代码,这样我们就不必重新编写它。给定链接包含代码。请在问题中添加代码。添加到问题的注释框中的代码不可读。感谢您提供的代码片段,因为这是一个xml文件,所以我决定使用XSLT处理xml文件。谢谢你的帮助。
>type file
<bookstores>
<book id="parent">
<name="it1"/>
<name="it1"/>
<name="it2"/>
</book>
<book id="child">
<name="it1"/>
<name="it1"/>
<name="it2"/>
<name="it3"/>
</book>
</bookstores>
>type dictionary
</book>
>script.bat
<bookstores>
<book id="parent">
<name="it1"/>
<name="it2"/>
</book>
<book id="child">
<name="it3"/>
</book>
</bookstores>