找回密码
 加入
搜索
查看: 5434|回复: 13

[效率算法] 文本有条件剪切.... [已解决]

  [复制链接]
发表于 2012-3-22 08:45:15 | 显示全部楼层 |阅读模式
本帖最后由 流沙枫 于 2012-3-22 14:46 编辑

add  caller-id="" comment="\B1\D5\CE\B0\C0\BCm"    disabled=yes name=201107 password=201107           profile=default routes="" service=pppoe                                                                              
add  caller-id="" comment="\B1\D5\D1\DE\D5\E4"     disabled=yes name=200902 password=200902          profile=default routes="" service=pppoe                                                                              
add  caller-id="" comment="\B1\F6\D6\F9\C3\F7m"    disabled=yes name=201002 password=201002           profile=default routes=""
service=pppoe


把name=2011的行剪切出来,再按升序排列?

name=201101
name=201102
不好意思了,又遇到难题,再次求助各位大大.....

评分

参与人数 1金钱 +15 收起 理由
afan + 15 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

 楼主| 发表于 2012-3-22 10:01:12 | 显示全部楼层
Local $sFile1 = @ScriptDir & '\test2011.rsc'
Local $sFile2 = @ScriptDir & '\2test2011.rsc'
Local $Str = FileRead($sFile1)
Local $scut = StringRegExp($str, '(?i)(.+\s+.+name=\h*(2011.+?)\h*\2')
If Not @Error And @Extended = 0 Then Exit MsgBox(48, '注意', '没 ')
Local $Extended = @Extended
FileDelete($sFile1)
If FileWrite($sFile1, $scut) Then MsgBox(64, '完成', '成功 ' & $Extended & ' 处 ')
改不出....
发表于 2012-3-22 10:29:09 | 显示全部楼层
试试? 不知大文件的效率如何?
但应该工作正常罢!
#include <array.au3>

$txt = FileRead('d:\new.rsc')
$line = StringRegExp($txt, '.+name=2011\d{2}.+', 3)
If @error Then Exit
$s = UBound($line)
Local $index[$s]
For $i = 0 To $s -1
        $Lable = StringRegExpReplace($line[$i], '.+(name=\d{6}).+', '\1') ; 提取关键字作为排列依据
        $index[$i] = $Lable
Next
_ArraySort($index)  ; 排列关键字
Local $str = ''
For $i = 0 To $s -1
        For $ii = 0 To $s -1
        If StringRegExp($line[$ii], $index[$i]) Then $str &= $line[$ii] & @CRLF ; 按关键字重组所胡字符串
Next
Next
FileWrite('d:\2011.rsc', $str)

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2012-3-22 10:40:18 | 显示全部楼层
回复 3# user3000
#include <array.au3>

Local $sFile1 = @ScriptDir & '\test2011.rsc'
Local $sFile2 = @ScriptDir & '\2test2011.rsc'
$line = StringRegExp($sFile1, '.+name=2011\d{2}.+', 3)
If @error Then Exit
$s = UBound($line)
Local $index[$s]
For $i = 0 To $s -1
        $Lable = StringRegExpReplace($line[$i], '.+(name=\d{6}).+', '\1') ; 提取关键字作为排列依据
        $index[$i] = $Lable
Next
_ArraySort($index)  ; 排列关键字
Local $str = ''
For $i = 0 To $s -1
        For $ii = 0 To $s -1
        If StringRegExp($line[$ii], $index[$i]) Then $str &= $line[$ii] & @CRLF ; 按关键字重组所胡字符串
Next
Next
FileWrite($sFile2, $str)
修改了下,无效的?
发表于 2012-3-22 10:52:02 | 显示全部楼层
回复  user3000 修改了下,无效的?
流沙枫 发表于 2012-3-22 10:40



    我...R..I...
你读文件的代码呢?
 楼主| 发表于 2012-3-22 11:02:02 | 显示全部楼层
回复 5# user3000


    Local $Str = FileRead($sFile1)?
加这行?
也不行呢.....
 楼主| 发表于 2012-3-22 11:05:43 | 显示全部楼层
回复 3# user3000


    用回这个也行了.....
发表于 2012-3-22 11:10:15 | 显示全部楼层
回复  user3000


    用回这个也行了.....
流沙枫 发表于 2012-3-22 11:05

把文件上传上来吧.
太大就截取一部分..
或者自己加 msgBox 等看看是不是正则工作不正常!
 楼主| 发表于 2012-3-22 11:10:35 | 显示全部楼层
回复 2# 流沙枫


     Array variable subscript badly formatted.:
Local $index[$s]
Local $index[^ ERROR
 楼主| 发表于 2012-3-22 11:14:46 | 显示全部楼层
回复 8# user3000


    都是和上面三行差不多的,数据不用都上传吧?
发表于 2012-3-22 11:21:54 | 显示全部楼层
本帖最后由 user3000 于 2012-3-22 11:25 编辑
回复  user3000


    都是和上面三行差不多的,数据不用都上传吧?
流沙枫 发表于 2012-3-22 11:14


这是我测试成功的数据...
运行环境:  AutoIt v3.3.7.15 (beta)中文版
那你自己对比, 慢慢找原因吧

本帖子中包含更多资源

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

×
 楼主| 发表于 2012-3-22 11:57:12 | 显示全部楼层
回复 11# user3000


    真的可以了,原来是改错代码了,不好意思啊,谢谢啊.....
 楼主| 发表于 2012-3-22 14:30:33 | 显示全部楼层
本帖最后由 流沙枫 于 2012-3-22 14:45 编辑

回复 11# user3000


3 返回全局匹配的数组.

原来是没好好学习,sorry了....
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-6 08:42 , Processed in 0.094142 second(s), 29 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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