我想从当前数组中删除孤儿(不匹配对):
J01171 01/11/2012 08:03:34 J01171 Bath Rd Ipswich Reconnected
J01171 01/11/2012 08:04:34 J01171 Bath Rd Ipswich Isolated by OTU Fault
J01171 01/11/2012 08:04:47 J01171 Bath Rd Ipswich Reconnected
J01171 02/01/2013 15:46:22 J01171 Bath Rd Ipswich Isolated by OTU Fault
J01171 02/01/2013 15:46:36 J01171 Bath Rd Ipswich Reconnected
J01171 01/02/2013 18:12:43 J01171 Bath Rd Ipswich Isolated by OTU Fault
J01171 01/02/2013 18:42:32 J01171 Bath Rd Ipswich Reconnected
J01181 10/12/2012 13:13:13 J01181 BathRd LeighRd Isolated by Fault
J01181 10/12/2012 15:30:01 J01181 BathRd LeighRd Reconnected
J01181 09/02/2013 00:43:00 J01181 BathRd LeighRd Isolated by OTU Fault
J01181 09/02/2013 00:47:57 J01181 BathRd LeighRd Reconnected
J01181 09/02/2013 00:49:00 J01181 BathRd LeighRd Isolated by OTU Fault
删除孤儿后,输出应该是这样的:
J01171 01/11/2012 08:04:34 J01171 Bath Rd Ipswich Isolated by OTU Fault
J01171 01/11/2012 08:04:47 J01171 Bath Rd Ipswich Reconnected
J01171 02/01/2013 15:46:22 J01171 Bath Rd Ipswich Isolated by OTU Fault
J01171 02/01/2013 15:46:36 J01171 Bath Rd Ipswich Reconnected
J01171 01/02/2013 18:12:43 J01171 Bath Rd Ipswich Isolated by OTU Fault
J01171 01/02/2013 18:42:32 J01171 Bath Rd Ipswich Reconnected
J01181 10/12/2012 13:13:13 J01181 BathRd LeighRd Isolated by Fault
J01181 10/12/2012 15:30:01 J01181 BathRd LeighRd Reconnected
J01181 09/02/2013 00:43:00 J01181 BathRd LeighRd Isolated by OTU Fault
J01181 09/02/2013 00:47:57 J01181 BathRd LeighRd Reconnected
对于所有资产代码,排序数组中的所有元素都成对“隔离 - 重新连接”。但是,该数组有一些资产代码的孤儿:顶部有不匹配的“重新连接”(因为它的“孤立”对已留在其他日志文件中),底部有不匹配的“孤立” (因为它的“重新连接”对将在未来的日志文件中)。我的任务是摆脱所有的孤儿。我在这里只放了 2 个资产代码,但实际上有数百个(甚至可能是数千个)资产代码,数组中有 50 万个元素,因此有数百个孤儿。
孤儿也可能出现在资产代码的中间。基本上,在任何给定资产代码的中间可能会出现三个“隔离”相互跟随的情况。我需要在第一个“孤立”之后删除以下“孤立”-s,因为它还没有得到它的对。例如,
X00000 dd/mm/yyyy hh:mm:ss X00000 qwerty Isolated
X00000 dd/mm/yyyy hh:mm:ss X00000 qwerty Isolated [NEEDS TO BE REMOVED]
X00000 dd/mm/yyyy hh:mm:ss X00000 qwerty Isolated [NEEDS TO BE REMOVED]
X00000 dd/mm/yyyy hh:mm:ss X00000 qwerty Reconnected
J00000 dd/mm/yyyy hh:mm:ss X00000 qwerty Isolated
J00000 dd/mm/yyyy hh:mm:ss X00000 qwerty Isolated [NEEDS TO BE REMOVED]
J00000 dd/mm/yyyy hh:mm:ss X00000 qwerty Reconnected
J00000 dd/mm/yyyy hh:mm:ss X00000 qwerty Reconnected [NEEDS TO BE REMOVED]
有什么想法可以解决这个问题吗?提前致谢。