找回密码
 加入
搜索
查看: 3192|回复: 7

[AU3基础] 如何删除文本中以指定数据开头的重复行

  [复制链接]
发表于 2010-4-29 11:13:27 | 显示全部楼层 |阅读模式
文本如下:
(OCC)COMBINATION #  1                                                         
10    2100     1684     6829       9691     9853     2136   Rigid ANC   
(OCC)COMBINATION #  1     
130       0        0     2740          0        0        0   Rigid +Z     
(OCC)COMBINATION #  2        
130       0     2964        0          0        0        0   Rigid GUI
(OCC)COMBINATION #  2   
130       0        0     2740          0        0        0   Rigid +Z      

要删除以(OCC)开头的重复行,变成:
(OCC)COMBINATION #  1                                                         
10    2100     1684     6829       9691     9853     2136   Rigid ANC   
  130       0        0     2740          0        0        0   Rigid +Z     
(OCC)COMBINATION #  2        
130       0     2964        0          0        0        0   Rigid GUI
130       0        0     2740          0        0        0   Rigid +Z   

请教脚本应该如何考虑呢?
发表于 2010-4-29 11:21:19 | 显示全部楼层
hehe !楼主又来一道正则题啊!
发表于 2010-4-29 11:31:29 | 显示全部楼层
回复 1# jchang
正则表达式真的很难,看的头都大了,还是处于混沌之中!!!
 楼主| 发表于 2010-4-29 11:53:51 | 显示全部楼层
呵呵,最近遇到的正则问题比较多
发表于 2010-4-29 14:45:55 | 显示全部楼层
字符串内容:
(OCC)COMBINATION #  1                                                         
10    2100     1684     6829       9691     9853     2136   Rigid ANC   
(OCC)COMBINATION #  2   
130       2100        223     2740          2740        0        0   Rigid +Z   
(OCC)COMBINATION #  2   
130       2600        223     2740          2740        0        0   Rigid +Z   
(OCC)COMBINATION #  1     
130       0        0     2740          0        0        0   Rigid +Z     
(OCC)COMBINATION #  2        
130       0     2964        0          0        0        0   Rigid GUI
(OCC)COMBINATION #  2   
130       0        0     2740          0        0        0   Rigid +Z     
#include <array.au3>
If FileExists("test.txt") Then FileDelete("test.txt")
$str=FileRead("1.txt");1.txt文件内容为楼主提供字符串
$arr=StringRegExp($str,'\([^()]*?\).+\n.+',3)
_ArraySort($arr)
;_ArrayDisplay($arr)
For $i=0 To UBound($arr)-1
        $str1=StringStripWS($arr[$i],4)
        $str2=StringReplace($str1,21,"=")        
        $arr2=StringSplit($str2,"=")        
        IniWrite("test.txt",$arr2[1],$i,$arr2[2])        
Next
MsgBox(0,0,StringRegExpReplace(FileRead("test.txt"),'\d=',''))

评分

参与人数 2金钱 +30 贡献 +1 收起 理由
jchang + 10 + 1
水木子 + 20 学习啦!

查看全部评分

发表于 2010-4-29 15:14:38 | 显示全部楼层
字符串内容:
3mile 发表于 2010-4-29 14:45

呵呵!居然用ini写回去,方法不错!学习了。
不过这样一来输出结果和楼主的要求有点出入,还需要再次整理下吧?
发表于 2010-4-29 16:08:07 | 显示全部楼层
本帖最后由 afan 于 2010-4-29 16:11 编辑

将1楼测试字符串保存为 'test.txt'
Local $file = FileOpen('test.txt'), $line, $_line, $str
While 1
        $line = FileReadLine($file)
        If @error = -1 Then ExitLoop
        $_line = StringRegExp($line, '^(\(OCC\).+?)\h+$', 3)
        If Not @error Then
                If Not IsDeclared('_' & $_line[0]) Then
                        Assign('_' & $_line[0], 0)
                        $str &= $line & @CRLF
                EndIf
        Else
                $str &= $line & @CRLF
        EndIf
WEnd
FileDelete('test_new.txt')
FileWrite('test_new.txt', $str)
ShellExecute('test_new.txt')

评分

参与人数 1金钱 +10 收起 理由
jchang + 10 多谢

查看全部评分

 楼主| 发表于 2010-4-30 22:46:15 | 显示全部楼层
多谢各位,该问题解决啦
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-22 08:30 , Processed in 0.099789 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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