我有一个包含这样的原始数据的文件:
RMR,IV,0000771702159,PO,189.63,193.5,3.87
REF,DP,00081
REF,MC,543908537
REF,19,27
REF,ST,0078742064345
DTM,097,20170130
RMR,IV,0000771702454,PO,202.5,202.5
REF,DP,00064
REF,MR,0020
REF,PO,5654748341
REF,MC,936705865
REF,19,18
REF,ST,0605388000255
DTM,097,20170302
RMR,IV,0000771702644,PO,36.26,37,0.74
REF,DP,00090
REF,MC,505304198
REF,19,26
REF,ST,0078742076270
DTM,097,20170322
RMR,IV,0000771702645,PO,107.31,109.5,2.19
REF,DP,00081
REF,MC,505303606
REF,19,27
REF,ST,0078742076270
DTM,097,20170322
我要做的是删除块中包含“REF,DP,00064”行的任何“块”数据 每个文本块都以一条以RMR开头并以DTM
开头的行结束的行开头所以我想最终删除以下行之间的部分:
RMR,IV,0000771702159,PO,189.63,193.5,3.87
REF,DP,00081
REF,MC,543908537
REF,19,27
REF,ST,0078742064345
DTM,097,20170130
-----------------------------------------
RMR,IV,0000771702454,PO,202.5,202.5
REF,DP,00064
REF,MR,0020
REF,PO,5654748341
REF,MC,936705865
REF,19,18
REF,ST,0605388000255
DTM,097,20170302
-----------------------------------------
RMR,IV,0000771702644,PO,36.26,37,0.74
REF,DP,00090
REF,MC,505304198
REF,19,26
REF,ST,0078742076270
DTM,097,20170322
RMR,IV,0000771702645,PO,107.31,109.5,2.19
REF,DP,00081
REF,MC,505303606
REF,19,27
REF,ST,0078742076270
DTM,097,20170322
最终结果应该是:
RMR,IV,0000771702159,PO,189.63,193.5,3.87
REF,DP,00081
REF,MC,543908537
REF,19,27
REF,ST,0078742064345
DTM,097,20170130
RMR,IV,0000771702644,PO,36.26,37,0.74
REF,DP,00090
REF,MC,505304198
REF,19,26
REF,ST,0078742076270
DTM,097,20170322
RMR,IV,0000771702645,PO,107.31,109.5,2.19
REF,DP,00081
REF,MC,505303606
REF,19,27
REF,ST,0078742076270
DTM,097,20170322
我已经搜索并找到了如何删除如果我正在搜索的是在开头但在我的情况下它在中间
感谢任何帮助。
答案 0 :(得分:0)
不需要宏,你可以使用一个正则表达式。
^RMR(?:(?!DTM).)*\RREF,DP,00064\R(?:(?!DTM).)*DTM.+?\R
EMPTY
检查Regular expression
和. matches newline
<强>解释强>
^ : begining of line
RMR : literally RMR
(?: : begin non capture group
(?!DTM) : negative lookahead, make sure we don't have DTM
. : any character
)* : non capture group repeated 0 or more times
\R : any kind of linebreak
REF,DP,00064\R : literally REF,DP,00064 followed by a line break
(?:(?!DTM).)* : same as above
DTM.+? : literally DTM followed 1 or more charcaters non greedy
\R : any kind of linebreak
给定示例的结果:
RMR,IV,0000771702159,PO,189.63,193.5,3.87
REF,DP,00081
REF,MC,543908537
REF,19,27
REF,ST,0078742064345
DTM,097,20170130
RMR,IV,0000771702644,PO,36.26,37,0.74
REF,DP,00090
REF,MC,505304198
REF,19,26
REF,ST,0078742076270
DTM,097,20170322
RMR,IV,0000771702645,PO,107.31,109.5,2.19
REF,DP,00081
REF,MC,505303606
REF,19,27
REF,ST,0078742076270
DTM,097,20170322