找回密码
 加入
搜索
查看: 2895|回复: 4

[系统综合] 再次请教关于返回文本文件内含相同关键字行信息的问题

[复制链接]
发表于 2012-8-12 00:56:36 | 显示全部楼层 |阅读模式
本帖最后由 fuinei 于 2012-8-12 00:59 编辑

各位好,7月27日曾发贴请教查找文件内容返回关键字除外特定列字符串重复所有行的内容(Link:http://www.autoitx.com/thread-33688-1-1.html)由于代码中包括正则和与数组相关的函数未能理解代码的意思,现遇到另外一个情况需根据附件中计算机名返回计算机名相同的行,参考afan版主的代码以2个附件为原始数据,返回结果中都存在一定的问题,希望各位可以指导一下,谢谢!
按照附件内容PCinfo1返回:
PC1        192.168.1.1
PC2        192.168.1.2
PC3        192.168.1.3
PC1        192.168.1.5
PC2        192.168.1.6
PC3        192.168.1.7
PCinfo2返回:
PC1        192.168.1.1
PC2        192.168.1.2
PC3        192.168.1.3
PC1        192.168.1.1
PC2        192.168.1.2
PC3        192.168.1.3
#include <File.au3>
#include <Array.au3>

Local $Detailinfo,$LineDetailinfo,$Computer
Local $Detaillist = InputBox("InputBox","请输入Status文本文件名称","","",250,130)
Local $list = @ScriptDir & "" & $Detaillist & ".txt"
$Result_log = @ScriptDir & "" & $Detaillist & "_duplicatioin.xls"

If FileExists($list) = 1 then
        If _FileReadToArray($list,$Detailinfo) = 0 Then
                MsgBox(48,"Error","读取原始数据文件失败,程序将退出!")
                Exit        
        EndIf
Else
        MsgBox(48,"Error","无法找到原始数据文件,程序将退出!")
        Exit
EndIf

Local $sOut = 'ComputerName' & @TAB & 'IP_Address' & @CRLF

If @error Then MsgBox(48, '', '错误')
For $i = 1 To UBound($Detailinfo) - 1 Step 2
        If IsDeclared($Detailinfo[$i]) Then
                $sOut &= Eval($Detailinfo[$i]) & $Detailinfo[$i - 1] & @CRLF
                Assign($Detailinfo[$i], '')
        Else
                Assign($Detailinfo[$i], $Detailinfo[$i - 1] & @CRLF)
        EndIf
Next
$file = FileOpen($Result_log,1)
If $file = -1 Then
        MsgBox(48,"Error","无法打开日志文件,程序将退出!")
        Exit
EndIf
FileWrite($file, $sOut)
FileClose($file)
MsgBox(0, 'Info', '程序已运行完成,请查看日志!')

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2012-8-13 09:50:41 | 显示全部楼层
#include <File.au3>
#include <Array.au3>

Local $Detailinfo,$LineDetailinfo,$Computer
Local $Detaillist = InputBox("InputBox","请输入Status文本文件名称","","",250,130)
Local $list = @ScriptDir & "\" & $Detaillist & ".txt"
$Result_log = @ScriptDir & "\" & $Detaillist & "_duplicatioin.xls"

If FileExists($list) = 1 then
    $str=FileRead($list)
        $array=StringRegExp($str&@CRLF,'(?m)(^.*\r\n)(?=[^\1]*\1)',4)
Else
        MsgBox(48,"Error","无法找到原始数据文件,程序将退出!")
    Exit
EndIf

Local $sOut=""
$sOut&=$Result_log&@CRLF

For $i=0 To UBound($array)-1
        $temp=$array[$i]
        For $n=0 To UBound($temp)-1
                $sOut&=$temp[$n]
        Next
Next

$file = FileOpen($Result_log,1)
If $file = -1 Then
        MsgBox(48,"Error","无法打开日志文件,程序将退出!")
        Exit
EndIf
FileWrite($file, $sOut)
FileClose($file)
MsgBox(0, 'Info', '程序已运行完成,请查看日志!')
 楼主| 发表于 2012-8-14 17:02:25 | 显示全部楼层
回复 2# 3mile
谢谢指导,代码使用PCinfo1时返回的结果不正确并且我目前还不太了解正则,我折腾了很久目前使用以下代码可实现找到关键字重复的行,但代码的效率很低信息少时还好,信息量较大时执行(如7000行)需等待4分钟左右,不知各位有没有比较高效的返回重复行信息的方法呢?
#include <File.au3>
#include <Array.au3>
 
Local $Detailinfo,$Detailinfo_ex,$Duplicate = ""
Local $Detaillist = InputBox("InputBox","请输入Status文本文件名称","","",250,130)
Local $list = @ScriptDir & "" & $Detaillist & ".txt"
 
 
;判断Datasource文件能否读取/能否找到
If FileExists($list) = 1 then
        If _FileReadToArray($list,$Detailinfo) = 0 Then
                MsgBox(48,"Error","读取数据源文件失败,程序将退出!")
                Exit        
        EndIf
Else
        MsgBox(48,"Error","无法找到数据源文件,程序将退出!")
        Exit
EndIf 
 
;定义变量
$bound = UBound($Detailinfo)
Local $key[$bound]
Local $KeyName[$bound]
Local $Amount[$bound]

For $i = 1 To  $Detailinfo[0]
        $Detailinfo_ex = StringSplit($Detailinfo[$i],@TAB)
        $Key[$i] = $Detailinfo_ex[1]
        $KeyName[$i] = $Detailinfo_ex[1]
Next

For $i = 1 To $Detailinfo[0]
        ;使用_Arrayfindall判断是否有重复记录
        $Result = _ArrayFindAll($KeyName,$key[$i],0,0,0,2)
        $bound = UBound($Result)
        If $Result = -1 Then
                $Amount[$i] = 1
        Else
                $Amount[$i] = $bound
        EndIf

        If $Amount[$i] > 1 Then 
                $Duplicate &= "Line" & $i & @TAB & $Detailinfo[$i] & @CRLF
        EndIf
Next
        
MsgBox(0,"重复记录信息如下:",$Duplicate)
发表于 2012-8-14 18:42:16 | 显示全部楼层
回复 3# fuinei
只有正则才是最快的方法,几十万行才几秒钟,很给力的正则,可惜我不专啊!
 楼主| 发表于 2012-8-16 21:22:34 | 显示全部楼层
请问有没有可实现该功能的且执行效率较高的UDF呢?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-16 16:22 , Processed in 0.092861 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表