Board logo

标题: 几十万行记录对比? [打印本页]

作者: xmi     时间: 2008-6-25 22:26    标题: 几十万行记录对比?
有二个*.txt的文档, 每个文档有几十万行记录(文档内的每行记录都以 " ," 为分隔), 可不可以用批处理去把它们不相同一的放到别的文档呢? [ Last edited by xmi on 2008-6-25 at 10:33 PM ]

作者: HAT     时间: 2008-6-25 22:47
gawk "ARGIND==1{a[$0]}ARGIND>1&&!($0 in a){print $0}" a.txt b.txt >>c.txt
gawk.exe http://upload.cn-dos.net/img/548.zip [ Last edited by HAT on 2008-11-4 at 09:38 ]

作者: xmi     时间: 2008-6-25 22:53
HAT: 请问这个是什么东东来的, 和怎用? ??? 谢谢

作者: bat-zw     时间: 2008-6-25 23:07
@echo off
rem 查找2.txt与1.txt中不同的行
findstr /v /g:1.txt 2.txt>3.txt
start 3.txt
ps:就是效率不怎么样 [ Last edited by zw19750516 on 2008-6-25 at 11:11 PM ]

作者: HAT     时间: 2008-6-25 23:19
C:\Test>gawk --hlep Usage: gawk [POSIX or GNU style options] -f progfile [--] file ... Usage: gawk [POSIX or GNU style options] [--] "program" file ... POSIX options: GNU long options: -f progfile --file=progfile -F fs --field-separator=fs -v var=val --assign=var=val -m[fr] val -W compat --compat -W copyleft --copyleft -W copyright --copyright -W dump-variables[=file] --dump-variables[=file] -W gen-po --gen-po -W help --help -W lint[=fatal] --lint[=fatal] -W lint-old --lint-old -W non-decimal-data --non-decimal-data -W profile[=file] --profile[=file] -W posix --posix -W re-interval --re-interval -W source=program-text --source=program-text -W traditional --traditional -W usage --usage -W version --version To report bugs, see node `Bugs' in `gawk.info', which is section `Reporting Problems and Bugs' in the printed version.
看帮助

作者: bat-zw     时间: 2008-6-25 23:23
首先请用文本自身的替换功能将1.txt中所有的,替换成空格
@echo off&setlocal enabledelayedexpansion
rem 查找1.txt与2.txt的不同之处
for /f "delims=" %%a in (1.txt) do (
     for %%i in (%%a) do (
          set "flag="
           findstr "%%i" 2.txt>nul&&set flag=A
           if not defined flag echo %%i>>3.txt
     )
)
start 3.txt
ps:效率更是慢得惊人,前提还要所有的数据中不包含空格。 [ Last edited by zw19750516 on 2008-6-25 at 11:27 PM ]

作者: xmi     时间: 2008-6-25 23:51
Originally posted by HAT at 2008-6-25 11:19 PM: 看帮助
hat兄, 我试过你给我的code
gawk "ARGIND==1{a[$0]}ARGIND>1&&!($0 in a){print $0}" a.txt b.txt >>c.txt
, 成功抓到.万分谢意! 但我看完help, 还是不会用, 它内狸没有ARGIND这个的解说?

作者: xmi     时间: 2008-6-25 23:53
Originally posted by zw19750516 at 2008-6-25 11:07 PM:
@echo off
rem 查找2.txt与1.txt中不同的行
findstr /v /g:1.txt 2.txt>3.txt
start 3.txt
ps:就是效率不怎么样 [ Last edited by zw19750516 on 2008-6-25 at 11:11 PM ]
谢谢zw19750516, 不能完全成功, 结果的输出有两者的不相同, 但也有相同的出现在3.txt......

作者: ZJHJ     时间: 2008-6-26 00:06
如果真是几十万行的话,效率确实是个问题.二个文件中如果不相同的愉多,时间会非常 惊人.一般简单的命令不会使你满意. 为了提高效率,一 必须用fc 去掉大量的相同行缩小范围 .二 再在结果中去掉重复行 如果你要求一一对应,不相同的行又多,恐怕你的机器再好,也要运行几分钟或几个小时 或更多时间

作者: lxmxn     时间: 2008-6-26 00:19
几十万行,我想是不是可以导入到数据库中用SQL来的快些?

作者: xmi     时间: 2008-6-26 00:23
Originally posted by lxmxn at 2008-6-26 12:19 AM: 几十万行,我想是不是可以导入到数据库中用SQL来的快些?
是个txt档来的呀, 可以吗?

作者: HAT     时间: 2008-6-26 09:53
Originally posted by xmi at 2008-6-25 11:51 PM: hat兄, 我试过你给我的code
gawk "ARGIND==1{a[$0]}ARGIND>1&&!($0 in a){print $0}" a.txt b.txt >>c.txt
, 成功抓到.万分谢意! 但我看完h ...
建议到ChinaUnix的Shell版潜水一段时间^_^