Chinaunix

标题: 哪种方式可以最快完成N多字段对百兆级别的替换操作?! [打印本页]

作者: sunkey    时间: 2005-01-10 14:34
标题: 哪种方式可以最快完成N多字段对百兆级别的替换操作?!
需要完成的操作是把大概100~1000个特殊字段由大写改成小写,
输出到另外一个文档中,处理的文档一般都是100M到1.5G的超大文本。

我现在用的方法是sed :

sed -f cmd.list  xxxx.file > yyyy.file

其中, cmd.list  就是需要替换的所有的字段:

....
s/XXXBBB/xxxbbb/g
s/YYYAAA/yyyaaa/g
.....

这样处理一个文档,短则10~20分钟,长的则可能到2~4个小时。。。。

对于这样的处理,还有没有别的更好更快捷的替换方法??

请高手指教!!
作者: sunkey    时间: 2005-01-10 14:51
标题: 哪种方式可以最快完成N多字段对百兆级别的替换操作?!
别沉咯。。。

人心散了,队伍不好带啊。。。。
作者: r2007    时间: 2005-01-10 15:07
标题: 哪种方式可以最快完成N多字段对百兆级别的替换操作?!
替换处理是sed的强项,工具肯定是选对了.
作者: waker    时间: 2005-01-10 16:06
标题: 哪种方式可以最快完成N多字段对百兆级别的替换操作?!
sed1line中指出
/XXXBBB/ s//xxxbbb/g 比
s/XXXBBB/xxxbbb/g 要快
作者: sunkey    时间: 2005-01-10 17:46
标题: 哪种方式可以最快完成N多字段对百兆级别的替换操作?!
/XXXBBB/ s//xxxbbb/g

也是sed可以识别的语法么? 我试试看看能不能快一电。。 :)
作者: 哈    时间: 2005-01-10 18:01
标题: 哪种方式可以最快完成N多字段对百兆级别的替换操作?!
对于如此巨文可能下面的方式能快一点
  1. ed file < ed-cmd-file
复制代码

作者: sunkey    时间: 2005-01-11 10:09
标题: 哪种方式可以最快完成N多字段对百兆级别的替换操作?!
[quote]原帖由 "哈"][/quote 发表:



  ed file < ed-cmd  

  ed-cmd 里面是不是就是那些 s/XXXBBB/xxxbbb/g 命令?

   不work啊
作者: sunkey    时间: 2005-01-11 11:57
标题: 哪种方式可以最快完成N多字段对百兆级别的替换操作?!
原帖由 "waker" 发表:
sed1line中指出
/XXXBBB/ s//xxxbbb/g 比
s/XXXBBB/xxxbbb/g 要快



       

   I TRIED WITH THE SAME FILE,  IT WILL BE FUSTER MORE THAN
   20% ~~~!   

   CAN U TELL ME THE DIFFERENCE OF THIS COMMAND ??

    THX!!
作者: waker    时间: 2005-01-11 12:29
标题: 哪种方式可以最快完成N多字段对百兆级别的替换操作?!
I CAN NOT


作者: lightspeed    时间: 2005-01-11 12:56
标题: 哪种方式可以最快完成N多字段对百兆级别的替换操作?!
Please try AWK which should be faster than SED.
作者: sunkey    时间: 2005-01-11 13:47
标题: 哪种方式可以最快完成N多字段对百兆级别的替换操作?!
[quote]原帖由 "lightspeed"]Please try AWK which should be faster than SED.[/quote 发表:


I think  AWK is hard to do about thouthands 'find/replace' for a huge
text in global range ....

  How about the 'perl' ?  which can open one any size file and read
into the memory for processing....
作者: lightspeed    时间: 2005-01-11 23:02
标题: 哪种方式可以最快完成N多字段对百兆级别的替换操作?!
原帖由 "sunkey" 发表:


I think  AWK is hard to do about thouthands 'find/replace' for a huge
text in global range ....

  How about the 'perl' ?  which can open one any size file and read
into the memory for proces..........


It depends on what awk it is.  gawk can reach the limitation of file system.  Why don't you test it?

Awk is same as sed to process file line by line. In general,  awk
is much faster than sed due to DFA instead of NFA algorithm.

Perl is also a good choice.




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2