使用windows命令行解析XML

使用windows命令行解析XML,xml,parsing,cmd,Xml,Parsing,Cmd,如何将符合特定条件的完整行从XML(大小为1GB)提取到不同的新文件中 下面是一个例子: 示例XML文件 <?xml version="1.0" encoding="UTF-16"?> <root> <metadata xmlns="log"> <filename>QServer_64Trans_6576_20150325_1049_0.xml</filename> <date>25-03-2015</date>

如何将符合特定条件的完整行从XML(大小为1GB)提取到不同的新文件中

下面是一个例子:

示例XML文件

 <?xml version="1.0" encoding="UTF-16"?>
<root>
<metadata xmlns="log"> <filename>QServer_64Trans_6576_20150325_1049_0.xml</filename> <date>25-03-2015</date> <executablename>E:/Program Files/Quintiq/Quintiq 4.4.0/Bin/QServer_64.exe</executablename> <originalfilename>QServer_64.exe</originalfilename> <productname>Quintiq Server 64-bit</productname> <productversion>4.4.0.13</productversion> <specialbuilddescription>Changelist: 60074</specialbuilddescription> <loggerversion>1.1</loggerversion> </metadata>
<logentries xmlns="log">
<logentry> <index>233509</index> <jobid>14442692</jobid> <status>Finished</status> <result></result> <transactionid>816712145</transactionid> <transactionkind>JobDefinition</transactionkind> <threadname>Trans_0</threadname> <threadid>5912</threadid> <starttime>12:29:50</starttime> <endtime>12:29:50</endtime> <length>00:00:00.031</length> <waitingtime>00:00:00.000</waitingtime> <proctime>00:00:00.015</proctime> <functime>00:00:00.000</functime> <dbtime>00:00:00.016</dbtime> <streamtime>00:00:00.000</streamtime> <nrdatasets>0</nrdatasets> <size>858</size> <constructions>0</constructions> <destructions>0</destructions> <changes>1</changes> <clientid>0</clientid> <ipclient></ipclient> <username>$system/SYSTEM</username> <actionelementtype>Company</actionelementtype> <actionelementname>NotifySenderRecipientAvailable</actionelementname> <actionelementkey>[706273.0.113959]</actionelementkey> <description></description> <messageid></messageid> <lockprofile>[N.[706272.0.12777530]]</lockprofile> <procmem>6744</procmem> <funcmem>126720</funcmem> <dbmem>2696</dbmem> <streammem>6288</streammem> <osvmsize></osvmsize> <freememory></freememory>  </logentry>
<logentry> <index>233510</index> <jobid>14442726</jobid> <status>Started</status> <result></result> <transactionid>816711772</transactionid> <transactionkind>Daemon</transactionkind> <threadname>Trans_1</threadname> <threadid>6208</threadid> <starttime>12:29:51</starttime> <endtime></endtime> <length></length> <waitingtime></waitingtime> <proctime></proctime> <functime></functime> <dbtime></dbtime> <streamtime></streamtime> <nrdatasets></nrdatasets> <size></size> <constructions></constructions> <destructions></destructions> <changes></changes> <clientid>0</clientid> <ipclient></ipclient> <username></username> <actionelementtype>Company</actionelementtype> <actionelementname>DaemonTimedEventHandler</actionelementname> <actionelementkey>[706273.0.88663]</actionelementkey> <description></description> <messageid></messageid> <lockprofile>[N.[706272.0.12777530]]</lockprofile> <procmem></procmem> <funcmem></funcmem> <dbmem></dbmem> <streammem></streammem> <osvmsize></osvmsize> <freememory></freememory>  </logentry>
<logentry> <index>233511</index> <jobid>14442757</jobid> <status>Started</status> <result></result> <transactionid>816712147</transactionid> <transactionkind>ExternalCallMessage</transactionkind> <threadname>Trans_0</threadname> <threadid>5912</threadid> <starttime>12:29:51</starttime> <endtime></endtime> <length></length> <waitingtime></waitingtime> <proctime></proctime> <functime></functime> <dbtime></dbtime> <streamtime></streamtime> <nrdatasets></nrdatasets> <size></size> <constructions></constructions> <destructions></destructions> <changes></changes> <clientid>1290</clientid> <ipclient>10.48.84.220</ipclient> <username>active directory/jonathangonsalvez</username> <actionelementtype>TicketOfWorkCustom</actionelementtype> <actionelementname>Update</actionelementname> <actionelementkey>[103648.0.1464376049]</actionelementkey> <description>BoundCall on INST</description> <messageid></messageid> <lockprofile>[N.[706272.23.358965396]]</lockprofile> <procmem></procmem> <funcmem></funcmem> <dbmem></dbmem> <streammem></streammem> <osvmsize></osvmsize> <freememory></freememory>  </logentry>
<logentry> <index>233512</index> <jobid>14442726</jobid> <status>Finished</status><result></result> <transactionid>816711772</transactionid> <transactionkind>Daemon</transactionkind><threadname>Trans_1</threadname> <threadid>6208</threadid> <starttime>12:29:51</starttime> <endtime>12:29:51</endtime> <length>00:00:00.078</length> <waitingtime>00:00:00.000</waitingtime> <proctime>00:00:00.047</proctime> <functime>00:00:00.000</functime> <dbtime>00:00:00.031</dbtime> <streamtime>00:00:00.002</streamtime> <nrdatasets>0</nrdatasets> <size>6595</size> <constructions>0</constructions> <destructions>1</destructions> <changes>3</changes> <clientid>0</clientid> <ipclient></ipclient> <username></username> <actionelementtype>Company</actionelementtype> <actionelementname>DaemonTimedEventHandler</actionelementname> <actionelementkey>[706273.0.88663]</actionelementkey> <description></description> <messageid></messageid> <lockprofile>[N.[706272.0.12777530]]</lockprofile> <procmem>1060016</procmem> <funcmem>126696</funcmem> <dbmem>2832</dbmem> <streammem>32688</streammem> <osvmsize></osvmsize> <freememory></freememory>  </logentry>
</logentries>
</root>

QServer_64Trans_6576_20150325_1049_0.xml 25-03-2015 E:/Program Files/Quintiq/Quintiq 4.4.0/Bin/QServer_64.exe QServer_64.exe Quintiq Server 64位4.4.0.13变更列表:60074 1.1
233509 14442692完成816712145作业定义Trans_0 5912 12:29:50 12:29:50 00:00:00.031 00:00:00:00.015 00:00:00:00.016 00:00:00:00.000 0 858 0 0 1 0$system/system Company NotifyerRecipientAvailable[706273.0.113959][N.[706272.0.12777530]]6744 126720 2696 6288
233510 14442726已启动816711772后台程序Trans_1 6208 12:29:51 0公司DaemonTimedEventHandler[706273.0.88663][N.[706272.0.12777530]]
233511 14442757在INST上启动816712147外部调用消息传输0 5912:29:51 1290 10.48.84.220 active directory/jonathangonsalvez TicketofWork自定义更新[103648.0.1464376049]边界调用[N.[706272.23.358965396]
233512 14442726完成816711772 DaemonTrans_1 6208 12:29:51 12:29:51 00:00:00.078 00:00:00.047 00:00:00.000 00:00:00.031 00:00:00.002 0 6595 0 1 30 DaemonTimedEventHandler公司[706273.0.88663][N.[706272.0.12777530]]1060016 126696 2832 32688
搜索条件: 具有“完成”状态和“守护进程”作为事务类型的“日志条目”行。

<logentry>     <status>Finished</status>     <transactionkind>Daemon</transactionkind>
Finished守护进程

XML文件中所有符合此条件的行都应该使用windows命令行移动到新的文本文件中。

我会先说“使用C#或XSLT”或“omgwtf?powershell!”,然后读1GB部分。除非您可以将文件加载到RAM中,否则必须使用
XmlReader

如果您不介意恶心,请尝试
findstr/v Started input.xml>out.xml
。这将获取
input.xml
中不包含单词start的所有行。但是,不能保证这不会严重损坏XML

以下是powershell供参考:

$xml = [xml](Get-Content .\input.xml)
$xml.Root.LogEntries.LogEntry | where { $_.status -eq "Finished" } | ft

我在Linux服务器上或使用Cygwin找到了一个解决方案;但是不能使用任何与linux相关的东西。从新创建的.txt文件中提取特定守护进程的“已完成”记录,并将这些事件输出到下一个文件,即那些事件
grep“DaemonCompanyTime”QServer_64Trans_*\u 2015*.xml | grep Finished>DaemonCompanyTime_2015.csv
用双引号替换xml标记(文件将缩小约70%,原始版本保留在.bak文件中)
sed-i.bak's/]*>/“/g'DaemonCompanyTime_2015.csv