现有大量.txt格式文本文件,其中内容为数据报表,呈现固定格式,现想提取其中部分异常数据,如何实现?如在“平均分”数据列里出现了大于100或小于0的数值,刚该数据为要提取的对象。注:数据量很大,搜索量很大

解决方案 »

  1.   

    把所有.txt格式文本文件的文件路径全放到数组里.循环依次打开,从打开的文本中提取其中部分异常数据,存放在一个新建的.txt文件里.
      

  2.   

    可以用 ADO 访问固定格式的文本文件:http://topic.csdn.net/u/20070906/10/fcd627e0-bc57-4e91-b395-9ba85d67d2c1.html
    Schema.ini 格式 http://blog.chinahr.com/blog/CareyBobo/post/57874
      

  3.   

    最好是把文本文件转换成数据库,或者如楼上的用ADO访问文本文件,
    然后用查询语句来查询异常数据.
      

  4.   

    为了让大家更好的理解,附上我的数据如下:
    SN LCC-CD      WARM-UP-LAL        WARM-DW-LAL            LA-CNT  JK-CN
    01 7406               0.00          43,992.27              0.00      0
    02 7407               0.00          21,482.95              16.3      0
    03 7417             732.05               0.00              0.00      0
    04 841          364,827.50               0.00      1,614,973.45     91诸如以上格式的大量数据,“SN”、“LCC-CD”、“WARM-UP-LAL”、“LA-CNT”、“JK-CN”为字段名,下面为具体数据,现我想提取的是:“LCC-CD”列值为“7407”的行且该行“LA-CNT”列的值大于0.00。请高手指教,谢谢先!
      

  5.   

    为了让大家更好的理解,附上我的数据如下:
    SN   LCC-CD      WARM-UP-LAL        WARM-DW-LAL            LA-CNT  JK-CN
    01   7406               0.00          43,992.27              0.00      0
    02   7407               0.00          21,482.95              16.3      0
    03   7417             732.05               0.00              0.00      0
    04   841          364,827.50               0.00      1,614,973.45     91诸如以上格式的大量数据,“SN”、“LCC-CD”、“WARM-UP-LAL”、“LA-CNT”、“JK-CN”为字段名,下面为具体数据,现我想提取的是:“LCC-CD”列值为“7407”的行且该行“LA-CNT”列的值大于0.00。请高手指教,谢谢先!
      

  6.   

    dim strarr() as string, strline as string, i as integeropen "test.txt" for input as #1
    line input #1, strline    'skip header linedo until eof(1)
        line input #1, strline
        do while instr(strline, space(2))
            strline = replace(strline, space(2), space(1))
        loop
        strarr = split(strline, space(1))
        if ubound(strarr) then
            if strarr(1) = "7407" and strarr(4) > "0.00" then list1.additem replace(strline, space(1), vbtab)
        endif
    loop  
      

  7.   

    我的数据发上去,格式有些变,“SN”、“LCC-CD”两列是左对齐的,后面四列都是右对齐的
      

  8.   

    就是空格。dim strarr() as string, strline as string, strtmp as string, i as integer open "test.txt" for input as #1 
    open "newfile.txt" for output as #2
    line input #1, strline    'skip header line do until eof(1) 
        line input #1, strline
        strtmp = strline 
        do while instr(strtmp, space(2)) 
            strtmp = replace(strtmp, space(2), space(1)) 
        loop 
        strarr = split(strtmp, space(1)) 
        if ubound(strarr) then 
            if strarr(1) = "7407" and strarr(4) > "0.00" then print #2, strline 
        endif 
    loop 
    close #2
    close #1
      

  9.   

    我现在想把同一目录下的每一个源文本文件经过以上数据提取后,生成相应新文件,同文件名,存放在另一个目录下.如源文件目录为:C:\sourcedata\01\01.txt,
       C:\sourcedata\02\02.txt,
       C:\sourcedata\02\03.txt,
       C:\sourcedata\02\04.txt,
       C:\sourcedata\02\05.txt.
    现要把新生成的文件存到如下路径:
       C:\destinationdata\01\01.txt,
       C:\destinationdata\02\02.txt,
       C:\destinationdata\03\03.txt,
       C:\destinationdata\04\04.txt,
       C:\destinationdata\05\05.txt,
    就是将sourcedata目录换成了destinationdata目录,子目录和文件名是一样的。
    整个过程等与:遍历sourcedata目录,提取数据,生成新文件,放在destinationdata目录下。高手请帮忙,急用