如何根据关键字提取标签中出现的完整文本



我有一个日志文件,其中包含以下格式的内容:

<webdoc>

详细信息属于多线客户

<webdoc>

ORA-01461:只能绑定LONG值以插入LONG列

现在,我想做的是在一天结束时运行一个脚本,查找关键字ORA-01461,如果出现,则从关键字之前出现的客户标记内部提取内容,并存储在文本文件中。

让我给你一些伪代码:

boolean bCustomer = false;
string l = "";
File fIntermediate;
while not eof{
l = readline();
if l = "<customer>" or l="</customer>" or l.contains("ORA-01161") or bCustomer
then fIntermediate.addAtTheBeginning(l);
if l = "</customer>"
then bCustomer = False;
if l = "<customer>"
then bCustomer = True;
}

该代码的结果将生成一个中间文件&""ORA"以及";客户";标签以相反的顺序排列(因此为addAtTheBeginning()(。

然后,使用类似的布尔值bORA-01161_found读取该中间文件,将False作为起始值。您读取了中间文件。一旦找到CCD_ 4,就将提及布尔值设置为CCD_&"lt/客户";也不是";ORA-01161";并且提到的布尔值是True,则将内容写入到生成的文本文件中。

p.s.首先要确保您的标记名是正确的:首先询问"客户";,并且当写一个答案时,相应地将其变为"0";webdoc";有点奇怪:-(

相关内容

最新更新