需要帮助解析文本-日志文件并在该文件中找到EOL字符. [英] Need help parsing the text - log file and find EOL character in that file.

查看:62
本文介绍了需要帮助解析文本-日志文件并在该文件中找到EOL字符.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个奇怪的问题.我正在使用简单的HTA程序 来读取文本文件(.log文件)并将其分成以下几行
I have a strange problem. I am using simple HTA program  to read the text file (.log file) and split it into lines as following

推荐答案

您好,


服务器生成的日志文件中有一行扫描.例如
"Quick Brown Fox跳过了那只懒狗. Alpha Beta = Gamma"

现在,如果我在记事本中打开上述行(默认),则显示为单行,但是如果我在写字板(Windows)中将其打开,则应该就像两行在Aplha前面留有空格一样.

Quick Brown Fox跳过了那只懒惰的狗.
  Alpha Beta = Gamma

带有上述问题 我今天用可能的替代品进行了一些测试,这是我发现的结果.

==> ReadAll可以像记事本一样读取文件,脚本可以正常工作,直到我发现服务器生成的某些文件无法正确读取(请参阅我的第一篇文章),这意味着VBCRLF会混淆ReadAll函数
==>我测试了然后如下所示

直到objFile.AtEndOfStream
        ReDim保留TextArray(i)
       TextArra(i)= objFile.ReadLine
       i = i + 1
 循环
FileText  = Join(TextArray,VbCRLf)

通过上面的代码,我发现上面的字符串分为两行,就像写字板一样.每当Quick Brown Fox出现在一行中以捕获Aplha和Beta值时,我都必须对脚本进行重大更改以扫描下一行.这是否也意味着记事本忽略了写字板可以看到的某些LF字符CR.
==>我也用Adodb.stream和charset ascii进行了测试..mode是admode read
这次可以工作了(似乎像记事本一样读取文件,就像读取文件一样),但是不幸的是,与上述方法相比,加载文件花费了将近5倍的时间,而这对我来说是行不通的.
函数ReadLog(sFileSpec)
  const adTypeText = 2
  const adModeReadWrite = 3
 使用CreateObject("ADODB.Stream")
    .type = adTypeText
    .mode = adModeRead
    .charset ="ascii"
    .open
    .LoadFromFile sFileSpec
    ReadLog = .readText
结尾为
结束功能为

所以我的问题是,有一种方法可以加载文件以仅使用ADODB.stream快速读取,从而可以解决此问题.解决我的问题,避免使用readline,这会导致我的长期运行和额外的循环.
或者,是否可以在使用objFile时更改文件的字符集?
请记住,原始代码(File Text = objFile.ReadAll)仅在某些文件上失败,并且如果我将约束复制到新文件中,则相同的脚本可以正常工作.
来自某人的任何人...
非常感谢...
Aray
Hi,


Log file generated by my server has a line which I need to scan. E.g
"Quick Brown Fox jumps over the lazy dog. Alpha Beta = Gamma "

Now if I open the above line in notepad (default) , it shows up as one single line but if I open this up in the WordPad (windows), it should this like two lines with a space in front of Aplha.

Quick Brown Fox jumps over the lazy dog.
 Alpha Beta = Gamma

With above issue  I did some testing today with possible alternatives and here is what i found.

==> ReadAll reads the file just like notepad and script works fine until i found that some files generated by server are not read correctly (see my first post), meaning that somwhere VBCRLF is confusing the ReadAll function
==>I tested then as following

Do Until objFile.AtEndOfStream
        ReDim Preserve TextArray(i)
        TextArra(i) = objFile.ReadLine
        i = i + 1
 Loop
FileText  = Join(TextArray, VbCRLf)

With above code , i found that above string is divided into two lines, just like wordpad. I have to make major changes in the script to scan next line every time Quick Brown Fox appers in a line to catch Aplha and Beta values. Does this also means that notepad is ignoring some CR of LF character that wordpad can see.
==>I also tested with Adodb.stream with charset ascii and .mode is admode read
This time it worked (seems like file is read just like notepad did) but unfortunately it took almost 5 times more time to load the file as compared to above method which is not going to work for me.
Function ReadLog(sFileSpec)
  const adTypeText = 2
  const adModeReadWrite = 3
  With CreateObject("ADODB.Stream")
    .type = adTypeText
    .mode = adModeRead
    .Charset = "ascii"
    .open
    .LoadFromFile sFileSpec
    ReadLog = .readText
End with
End Funciton

So my question is that is there a way to load the file for reading only using ADODB.stream quickly so that I have workaround to my issue and avoid using readline which will cause me some grief in the long run and additional cycles.
Alternatively is there a way to change the characterset of a file when doing using objFile ? May be that is my problem.
remember that original code (File Text = objFile.ReadAll) fails only on certain files and if I copy the contects into new file, same script works fine.
Looking to hear from someone, anyone on this...
Thanks so much...
Aray


这篇关于需要帮助解析文本-日志文件并在该文件中找到EOL字符.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆