首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

通过对话框打开大体积文件提取关键字后显示并且通过对话框保存,该如何处理

2012-02-04 
通过对话框打开大体积文件提取关键字后显示并且通过对话框保存各位好心人,大哥,大侠你们好原文件是超过100

通过对话框打开大体积文件提取关键字后显示并且通过对话框保存
各位好心人,大哥,大侠
  你们好
  原文件是超过100M的系统日志文件。文件名为 “日期.APX”如:“110606.APX” 内容为文本文件。
  从原始文件中提出 DATA 如 06/06/11; TIME 如 0:01:55 ; 级别 如 ** ; CELL号 如747; CDM号 如 2 ;DS1号 如 DS1-3
   


  请帮忙给个详细的解决办法,这里先谢谢各位的定力相助。
   
目标文件格式
DATATIME**CELLCDMDS1
06/06/110:01:55**7472DS1-3
06/06/110:01:56*7472DS1-3
06/06/110:06:505682DS1-1
06/06/110:07:00**5682DS1-1
06/06/110:12:015682DS1-1
06/06/110:12:07**5682DS1-1 

下面是原始文件内容文件名为XXXXXX.APX里面内容问文本

hf3omp bbomp307> gzcat 110606.APX.gz | cgrep +-w# "ALARM" | cgrep +-w# "DS1"
========================================
06/06/11 00:01:55 #713584

**01 REPT:CELL 747 CDM 2, CRC, HEH
  SUPPRESSED MSGS: 0
  ERROR TYPE: ONEBTS MODULAR CELL ERROR
  SET:DS1-3 ALARM

  01 11 00 00 00 00 00 00
  00 00 00 00 00 00 00 00
  00 00 00 00



06/06/11 00:01:55 #713586
========================================
06/06/11 00:01:56 #713592

* 01 REPT:CELL 747 CDM 2, CRC, HEH
  SUPPRESSED MSGS: 0
  ERROR TYPE: ONEBTS MODULAR CELL ERROR
  SET:DS1-3 ALARM

  01 01 00 00 00 00 00 00
  00 00 00 00 00 00 00 00
  00 00 00 00



06/06/11 00:01:56 #713593
========================================
06/06/11 00:06:50 #714922

  06 REPT:CELL 568 CDM 2, CRC, HEH
  SUPPRESSED MSGS: 0
  ERROR TYPE: ONEBTS MODULAR CELL ERROR
  SET:DS1-1 ALARM

  01 00 00 00 00 00 00 00
  00 00 00 00 00 00 00 00
  00 00 00 00



06/06/11 00:06:50 #714926
========================================
06/06/11 00:07:00 #714983

**07 REPT:CELL 568 CDM 2, CRC, HEH
  SUPPRESSED MSGS: 0
  ERROR TYPE: ONEBTS MODULAR CELL ERROR
  SET:DS1-1 ALARM

  01 20 00 00 00 00 00 00
  00 00 00 00 00 00 00 00
  00 00 00 00



06/06/11 00:07:00 #714984
========================================
06/06/11 00:12:01 #716318

  12 REPT:CELL 568 CDM 2, CRC, HEH
  SUPPRESSED MSGS: 2
  ERROR TYPE: ONEBTS MODULAR CELL ERROR
  SET:DS1-1 ALARM

  01 00 00 00 00 00 00 00
  00 00 00 00 00 00 00 00
  00 00 00 00



06/06/11 00:12:01 #716319
========================================
06/06/11 00:12:07 #716379

**12 REPT:CELL 568 CDM 2, CRC, HEH
  SUPPRESSED MSGS: 0
  ERROR TYPE: ONEBTS MODULAR CELL ERROR
  SET:DS1-1 ALARM

  01 20 00 00 00 00 00 00
  00 00 00 00 00 00 00 00
  00 00 00 00



06/06/11 00:12:07 #716380
========================================
06/06/11 00:28:31 #720824

  28 REPT:CELL 747 CDM 2, CRC, HEH
  SUPPRESSED MSGS: 2
  ERROR TYPE: ONEBTS MODULAR CELL ERROR
  SET:DS1-3 ALARM

  01 00 00 00 00 00 00 00
  00 00 00 00 00 00 00 00
  00 00 00 00



06/06/11 00:28:32 #720825

[解决办法]

VB.NET code
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click        Dim ofd As New OpenFileDialog        ofd.Filter = "APX文件|*.apx||"        If ofd.ShowDialog() <> Windows.Forms.DialogResult.OK Then Exit Sub        Dim data As String = System.IO.File.ReadAllText(ofd.FileName) '"110606.APX")        Dim mc As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(data, "(?n)(?m:^)(?<mask>(?<date>\d{2}(/\d{2}){2}) (?<time>\d{2}:\d{2}:\d{2})) #\d{6}.+\n\r\n(?<grade>\**).+?REPT:CELL\D+(?<cell>\d+)\s+CDM\s+(?<cdm>\d+)(.+\n){3}\s+SET:(?<ds1>\S+)[\s\S]+?\k<mask>.+")        Dim builder As New System.Text.StringBuilder        builder.AppendLine("DATA    TIME  **  CELL    CDM DS1")        For Each m As System.Text.RegularExpressions.Match In mc            builder.AppendLine(String.Format("{0}   {1} {2}    {3}   {4}  {5}", m.Groups("date"), m.Groups("time"), m.Groups("grade"), m.Groups("cell"), m.Groups("cdm"), m.Groups("ds1")))        Next        Dim sdf As New SaveFileDialog        sdf.Filter = "文本文件|*.txt||"        If sdf.ShowDialog() <> Windows.Forms.DialogResult.OK Then Exit Sub        System.IO.File.WriteAllText(sdf.FileName, builder.ToString())    End Sub 

热点排行