问题描述
我需要解析这种格式的文件,这样我就可以通过避免换行或/ n获取/获取存在的值代替那些标记,回车0r/ r,^^(空格) 。只是给我一个示例代码,这样可以帮助我继续......
i need to parse a file of this format,such that i can get/fetch the values present in place of those tags by avoiding linefeeds or "/n",carriage return 0r "/r",^^(spaces). just give me an idea with sample code such that it helps me in proceeding.....
^^^
M ^^^ COMPLD
(^^^[,]:,,, [],
[],[],[] [,]
[:[],[] [,
[,]]
[:[] [,]]])*;
^^^M^^^COMPLD(^^^"[,]:,,, [],[], [], [] [, ][:[], [] [,[,]][:[][,]]]")* ;
假设响应属于这种类型:我需要提取每个字段值,
ASSUME THAT RESPONSE IS OF THIS TYPE:i need to fetch each and every field value,
RTRV-HDR ::: RH01;
[2K
RTRV-HDR:::RH01;[2K
SIMULATOR 09-11-18 13:49:03
M RH01 COMPLD
;
代理商> RTRV-EQPT :: ALL:RE01;
[2K
SIMULATOR 09-11-18 13:49:03M RH01 COMPLD;agent>RTRV-EQPT::ALL:RE01;[2K
SIMULATOR 09-11-18 13:49:04
M RE01 COMPLD
SLOT-1-1- 1,CMP:IS-NR
SLOT-1-1-2,CMP:IS-NR
SLOT-1-1-3,OLC:IS-NR
SLOT-1-1-4,OLC:IS-NR
SLOT-1-1-5,OLC:IS-NR
SLOT-1-1-6,OLC:IS -NR
SLOT-1-1-7,OLC:IS-NR
SLOT-1-1-8,OLC:IS-NR
SLOT-1- 1-9,IOC:IS-NR
SLOT-1-1-10,IOC:IS-NR
SLOT-1-2-1,NMC:IS-NR
SLOT-1-2-2,NMC:IS-NR
SLOT-1-2-3,OLC:IS-NR
SLOT-1-2-4,OLC :IS-NR
SLOT-1-2-5,OLC:IS-NR
SLOT-1-2-6,OLC:IS-NR
SLOT- 1-2-7,OLC:IS-NR
SLOT-1-2-8,OLC:IS-NR
;
agent> RTRV-ALM-EQPT :: ALL:RA01;
[2K
SIMULATOR 09-11-18 13:49:04M RE01 COMPLD "SLOT-1-1-1,CMP:IS-NR" "SLOT-1-1-2,CMP:IS-NR" "SLOT-1-1-3,OLC:IS-NR" "SLOT-1-1-4,OLC:IS-NR" "SLOT-1-1-5,OLC:IS-NR" "SLOT-1-1-6,OLC:IS-NR" "SLOT-1-1-7,OLC:IS-NR" "SLOT-1-1-8,OLC:IS-NR" "SLOT-1-1-9,IOC:IS-NR" "SLOT-1-1-10,IOC:IS-NR" "SLOT-1-2-1,NMC:IS-NR" "SLOT-1-2-2,NMC:IS-NR" "SLOT-1-2-3,OLC:IS-NR" "SLOT-1-2-4,OLC:IS-NR" "SLOT-1-2-5,OLC:IS-NR" "SLOT-1-2-6,OLC:IS-NR" "SLOT-1-2-7,OLC:IS-NR" "SLOT-1-2-8,OLC:IS-NR";agent>RTRV-ALM-EQPT::ALL:RA01;[2K
SIMULATOR 09-11-18 13:49:05
M RA01 COMPLD
SLOT-1-1- 1,CMP:MN,T-FANCURRENT-1-HIGH,NSA,01-10-09,00-00-00 ,,:\Fan-T \,
SLOT-1- 1-1,CMP:MJ,T-BATTERYPWR-2-LOW,NSA,01-10-09,00-00-00 ,,:\Battery-T\,
SLOT- 1-1-2,CMP:CR,PROC_FAIL,SA,09-11-18,13-48-54 ,,:\处理器故障\,
SLOT-1-1-3 ,OLC:MN,T-LASERCURR-1-HIGH,SA,01-10-07,13-21-03 ,,:\Laser-T\,
SLOT-1-1 -3,OLC:MJ,T-LASERCURR-2-LOW,NSA,01-10-02,21-32-11 ,,:\Laser-T \,
SLOT-1 -1-4,OLC:MN,T-LASERCURR-1-HIGH,SA,01-10-05,02-14-03 ,,:\Laser-T\,
SLOT -1-1-4,OLC:MJ,T-LASERCURR-2-LOW,NSA,01-10-04,01-03-02 ,,:\Laser-T\,
;
agent> RTRV-ALM-EQPT :: ALL:RA02 :: MJ ,;
[2K
SIMULATOR 09-11-18 13:49:05M RA01 COMPLD "SLOT-1-1-1,CMP:MN,T-FANCURRENT-1-HIGH,NSA,01-10-09,00-00-00,,:\"Fan-T\"," "SLOT-1-1-1,CMP:MJ,T-BATTERYPWR-2-LOW,NSA,01-10-09,00-00-00,,:\"Battery-T\"," "SLOT-1-1-2,CMP:CR,PROC_FAIL,SA,09-11-18,13-48-54,,:\"Processor Failure\"," "SLOT-1-1-3,OLC:MN,T-LASERCURR-1-HIGH,SA, 01-10-07,13-21-03,,:\"Laser-T\"," "SLOT-1-1-3,OLC:MJ,T-LASERCURR-2-LOW,NSA, 01-10-02,21-32-11,,:\" Laser-T\"," "SLOT-1-1-4,OLC:MN,T-LASERCURR-1-HIGH,SA,01-10-05,02-14-03,,:\"Laser-T\"," "SLOT-1-1-4,OLC:MJ,T-LASERCURR-2-LOW,NSA,01-10-04,01-03-02,,:\"Laser-T\",";agent>RTRV-ALM-EQPT::ALL:RA02::MJ,;[2K
SIMULATOR 09-11-18 13:49:06
M RA02 COMPLD
SLOT-1-1- 1,CMP:MJ,T-BATTERYPWR-2-LOW,NSA,01-10-09,00-00-00 ,,:\Battery-T\,
SLOT-1- 1-3,OLC:MJ,T-LASERCURR-2-LOW,NSA,01-10-02,21-32-11 ,,:\Laser-T \,
SLOT- 1-1-4,OLC:MJ,T-LASERCURR-2-LOW,NSA,01-10-04,01-03-02 ,,:\Laser-T\,
;
代理> RTRV-ALM-EQPT :: ALL:RA03 :: MN ,;
[2K
SIMULATOR 09-11-18 13:49:06M RA02 COMPLD "SLOT-1-1-1,CMP:MJ,T-BATTERYPWR-2-LOW,NSA,01-10-09,00-00-00,,:\"Battery-T\"," "SLOT-1-1-3,OLC:MJ,T-LASERCURR-2-LOW,NSA, 01-10-02,21-32-11,,:\" Laser-T\"," "SLOT-1-1-4,OLC:MJ,T-LASERCURR-2-LOW,NSA,01-10-04,01-03-02,,:\"Laser-T\",";agent>RTRV-ALM-EQPT::ALL:RA03::MN,;[2K
SIMULATOR 09-11-18 13:49:06
M RA03 COMPLD
SLOT-1-1- 1,CMP:MN,T-FANCURRENT-1-HIGH,NSA,01-10-09,00-00-00 ,,:\Fan-T \,
SLOT-1- 1-3,OLC:MN,T-LASERCURR-1-HIGH,SA,01-10-07,13-21-03 ,,:\Laser-T\,
SLOT- 1-1-4,OLC:MN,T-LASERCURR-1-HIGH,SA,01-10-05,02-14-03 ,,:\Laser-T\,
;
agent> RTRV-ALM-EQPT :: ALL:RA04 :: MN,T-LASERCURR-1-HIGH;
[2K
SIMULATOR 09-11-18 13:49:06M RA03 COMPLD "SLOT-1-1-1,CMP:MN,T-FANCURRENT-1-HIGH,NSA,01-10-09,00-00-00,,:\"Fan-T\"," "SLOT-1-1-3,OLC:MN,T-LASERCURR-1-HIGH,SA, 01-10-07,13-21-03,,:\"Laser-T\"," "SLOT-1-1-4,OLC:MN,T-LASERCURR-1-HIGH,SA,01-10-05,02-14-03,,:\"Laser-T\",";agent>RTRV-ALM-EQPT::ALL:RA04::MN,T-LASERCURR-1-HIGH;[2K
SIMULATOR 09-11-18 13:49:10
M RA04 COMPLD
SLOT-1-1- 3,OLC:MN,T-LASERCURR-1-HIGH,SA,01-10-07,13-21-03 ,,:\Laser-T\,
SLOT-1- 1-4,OLC:MN,T-LASERCURR-1-HIGH,SA,01-10-05,02-14-03 ,,:\Laser-T\,
;
代理商> RTRV-PM-EQPT :: ALL:RP01;
[2K
SIMULATOR 09-11-18 13:49:10M RA04 COMPLD "SLOT-1-1-3,OLC:MN,T-LASERCURR-1-HIGH,SA, 01-10-07,13-21-03,,:\"Laser-T\"," "SLOT-1-1-4,OLC:MN,T-LASERCURR-1-HIGH,SA,01-10-05,02-14-03,,:\"Laser-T\",";agent>RTRV-PM-EQPT::ALL:RP01;[2K
SIMULATOR 09-11-18 13:49:11
M RP01 COMPLD
SLOT-1-1- 1,CMP:FANCURRENT-1,180.080 ,,,,,
SLOT-1-1-1,CMP:FANCURRENT-2,204.660 ,,,,,
SLOT-1-1-1, CMP:FANCURRENT-3,230.500 ,,,,,
SLOT-1-1-1,CMP:FANCURRENT-4,187.580 ,,,,,
SLOT-1-1-1,CMP: BATTERYPWR-1,53.650 ,,,,,
SLOT-1-1-1,CMP:BATTERYPWR-2,53.650 ,,,,,
SLOT-1-1-2, CMP:FANCURRENT-1,180.080 ,,,,,
SLOT-1-1-2,CMP:FANCURRENT-2,204.660 ,,,,,
SLOT-1-1-2,CMP: FANCURRENT-3,230.500 ,,,,,
SLOT-1-1-2,CMP:FANCURRENT-4,187.580 ,,,,,
SLOT-1-1-2,CMP:BATTERYPWR- 1,53.650 ,,,,,
SLOT-1-1-2,CMP:BATTERYPWR-2,53.650 ,,,,,
SLOT-1-1-3,OLC: LASERPWR-1,200.00 ,,,,,
SLOT-1-1-3,OLC:LASERPWR-2,200.00 ,,,,,
SLOT-1-1-4,OLC:LASERPWR- 1,200.00 ,,,,,
SLOT-1-1-4,OLC:LASERPWR-2,200.00 ,,,,,
SLOT-1-1-5,OLC:LASERPWR-1,200.00, ,,,,
SLOT-1-1-5,OLC:LASERPWR-2,200.00 ,,,,,
SLOT-1-1-6,OLC:LASER PWR-1,200.00 ,,,,,
SLOT-1-1-6,OLC:LASERPWR-2,200.00 ,,,,,
SLOT-1-1-7,OLC:LASERPWR- 1,200.00 ,,,,,
SLOT-1-1-7,OLC:LASERPWR-2,200.00 ,,,,,
SLOT-1-1-8,OLC:LASERPWR-1,200.00, ,,,,
SLOT-1-1-8,OLC:LASERPWR-2,200.00 ,,,,,
SLOT-1-2-3,OLC:LASERPWR-1,200.00 ,,,, ,,
SLOT-1-2-3,OLC:LASERPWR-2,200.00 ,,,,,
SLOT-1-2-4,OLC:LASERPWR-1,200.00 ,,,,,,
SLOT-1-2-4,OLC:LASERPWR-2,200.00 ,,,,,
SLOT-1-2-5,OLC:LASERPWR-1,200.00 ,,,,,
SLOT-1-2-5,OLC:LASERPWR-2,200.00 ,,,,,
SLOT-1-2-6,OLC:LASERPWR-1,200.00 ,,,,,
SLOT-1-2-6,OLC:LASERPWR-2,200.00 ,,,,,
SLOT-1-2-7,OLC:LASERPWR-1,200.00 ,,,,,
SLOT-1-2-7,OLC:LASERPWR-2,200.00 ,,,,,
SLOT-1-2-8,OLC:LASERPWR-1,200.00 ,,,,,
SLOT- 1-2-8,OLC:LASERPWR-2,200.00 ,,,,,
;
agent> INIT-SYS :: SLOT-1-1-2:IS01 :: 1;
[2K
SIMULATOR 09-11-18 13:49:11M RP01 COMPLD "SLOT-1-1-1,CMP:FANCURRENT-1,180.080,,,,," "SLOT-1-1-1,CMP:FANCURRENT-2,204.660,,,,," "SLOT-1-1-1,CMP:FANCURRENT-3,230.500,,,,," "SLOT-1-1-1,CMP:FANCURRENT-4,187.580,,,,," "SLOT-1-1-1,CMP:BATTERYPWR-1,53.650,,,,," "SLOT-1-1-1,CMP:BATTERYPWR-2,53.650,,,,," "SLOT-1-1-2,CMP:FANCURRENT-1,180.080,,,,," "SLOT-1-1-2,CMP:FANCURRENT-2,204.660,,,,," "SLOT-1-1-2,CMP:FANCURRENT-3,230.500,,,,," "SLOT-1-1-2,CMP:FANCURRENT-4,187.580,,,,," "SLOT-1-1-2,CMP:BATTERYPWR-1,53.650,,,,," "SLOT-1-1-2,CMP:BATTERYPWR-2,53.650,,,,," "SLOT-1-1-3,OLC:LASERPWR-1,200.00,,,,," "SLOT-1-1-3,OLC:LASERPWR-2,200.00,,,,," "SLOT-1-1-4,OLC:LASERPWR-1,200.00,,,,," "SLOT-1-1-4,OLC:LASERPWR-2,200.00,,,,," "SLOT-1-1-5,OLC:LASERPWR-1,200.00,,,,," "SLOT-1-1-5,OLC:LASERPWR-2,200.00,,,,," "SLOT-1-1-6,OLC:LASERPWR-1,200.00,,,,," "SLOT-1-1-6,OLC:LASERPWR-2,200.00,,,,," "SLOT-1-1-7,OLC:LASERPWR-1,200.00,,,,," "SLOT-1-1-7,OLC:LASERPWR-2,200.00,,,,," "SLOT-1-1-8,OLC:LASERPWR-1,200.00,,,,," "SLOT-1-1-8,OLC:LASERPWR-2,200.00,,,,," "SLOT-1-2-3,OLC:LASERPWR-1,200.00,,,,," "SLOT-1-2-3,OLC:LASERPWR-2,200.00,,,,," "SLOT-1-2-4,OLC:LASERPWR-1,200.00,,,,," "SLOT-1-2-4,OLC:LASERPWR-2,200.00,,,,," "SLOT-1-2-5,OLC:LASERPWR-1,200.00,,,,," "SLOT-1-2-5,OLC:LASERPWR-2,200.00,,,,," "SLOT-1-2-6,OLC:LASERPWR-1,200.00,,,,," "SLOT-1-2-6,OLC:LASERPWR-2,200.00,,,,," "SLOT-1-2-7,OLC:LASERPWR-1,200.00,,,,," "SLOT-1-2-7,OLC:LASERPWR-2,200.00,,,,," "SLOT-1-2-8,OLC:LASERPWR-1,200.00,,,,," "SLOT-1-2-8,OLC:LASERPWR-2,200.00,,,,,";agent>INIT-SYS::SLOT-1-1-2:IS01::1;[2K
SIMULATOR 09-11-18 13:49:11
M IS01 COMPLD
;
代理>
SIMULATOR 09-11-18 13:49:11M IS01 COMPLD;agent>
感谢所有有价值的回复
推荐答案
我认为你应该有一个动态聚合器,它接收输入并将相干线粘合在一起,使你的表达式更容易在这些行上做。 F.ex.你可以有一个Iterator,用你编写的那些行包装另一个迭代器,查找相干的行并将它们存储在StringBuffer中。当你发现所有相干线形成一行时,你将在next()方法中返回它。
I think you should have an on-the-fly aggregator which takes that input and glues coherent lines together, making your expressions easier to do on those lines instead. F.ex. you could have an Iterator which wraps another iterator with those lines you wrote, looks for coherent lines and storing those in a StringBuffer. When you've found all coherent lines to form one line you return it in the next() method.
这篇关于如何解析具有多个分隔符的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!