免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4324 | 回复: 10
打印 上一主题 下一主题

一个去重的问题,请看我详细的描述 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-08-03 17:45 |只看该作者 |倒序浏览
  1. cat file
  2. aaa|bbb|10
  3. aaa|bbb|8
  4. aaa|ccc|7
  5. aaa|bbb|9
复制代码
我想打印,
  1. aaa|bbb|10
  2. aaa|bbb|8
  3. aaa|bbb|9
复制代码
也就是说,我要打印前2个域相同,第三个域的差值小于10的所有行

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
2 [报告]
发表于 2010-08-03 17:50 |只看该作者
第三个域怎么个小于10?谁比谁小?
虽说不会,但理解起来很费解。

论坛徽章:
0
3 [报告]
发表于 2010-08-03 17:52 |只看该作者
你这个不是去重。。
和这个有点类似
http://bbs.chinaunix.net/thread-1760589-1-1.html

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
4 [报告]
发表于 2010-08-03 17:52 |只看该作者
100 95 91 89 80
这样的数列是不是一个都不打印?

论坛徽章:
0
5 [报告]
发表于 2010-08-03 18:00 |只看该作者
第三个域的差值小于10的所有行

我看至少30个汉字能把这句话解释得让人能明白

论坛徽章:
0
6 [报告]
发表于 2010-08-05 17:20 |只看该作者
回复 2# 昭襄王


    我表达的不明白

   我是想找每行中,前两个域相同,第三个域的数字相差小于10

    aaa|bbb|1
    aaa|bbb|2
    aaa|bbb|7

    1,2,7 之间相差在10以内

   aaa|bbb|15,如果是这个就不行了,因为已经比1,2 大于10了。 小于10是说,几个数中的任意两个相差都要小于10

论坛徽章:
0
7 [报告]
发表于 2010-08-05 18:04 |只看该作者
  1. awk -F '|' '{a[$1","$2]=$1","$2 in a?a[$1","$2]"\n"$0:$0;b[$1","$2]++}END{for (i in a) if (b[i]!=1) {T=0;split(a[i],m,"\n");for (j in m) c[n[split(m[j],n,"|")]];for (k in c) for (l in c) if (k-l>9||k-l<-9) {T=1;break}if (!T) print a[i]}}' file
复制代码

论坛徽章:
0
8 [报告]
发表于 2010-08-05 23:26 |只看该作者
  1. #!/bin/env awk

  2. BEGIN {
  3.     FS = "|"
  4. }

  5. {
  6.     word = $1$2
  7.     ++count[word]
  8.     matrix[word, $0]
  9.     if (! (word in min)) min[word] = $3
  10.     if (! (word in max)) max[word] = $3
  11.     $3 < min[word] && (min[word] = $3)
  12.     $3 > max[word] && (max[word] = $3)
  13. }

  14. END {
  15.     for (word in count) {
  16.         if (count[word] > 1) {
  17.             for (k in matrix) {
  18.                 split(k, idx, SUBSEP)
  19.                 if (idx[1] == word && max[word] - min[word] < 10) print idx[2]
  20.             }
  21.         }
  22.     }
  23. }
复制代码

论坛徽章:
0
9 [报告]
发表于 2010-08-06 02:02 |只看该作者
本帖最后由 黑色阳光_cu 于 2010-08-06 02:04 编辑

免费赠送一个tcl/tk版本

  1. wm title . filter
  2. button .btn -text "Open File..." -command filter
  3. text .t
  4. scrollbar .s
  5. .s config -command { .t yview }
  6. .t config -yscrollcommand { .s set }

  7. pack .btn
  8. pack .t -side left -expand 1 -fill both
  9. pack .s -side left -expand 0 -fill y

  10. proc filter {} {
  11.         set filename [tk_getOpenFile -initialdir .]
  12.         if {$filename == ""} {
  13.                 return
  14.         }

  15.         if [catch {set fp [open $filename r]}] {
  16.                 tk_messageBox -message "Could not open $filename!"
  17.                 return
  18.         }

  19.         .t delete 1.0 end
  20.         while {[gets $fp line] > -1} {
  21.                 set fields [split $line |]
  22.                 if {[llength $fields] < 3} {
  23.                         .t delete 1.0 end
  24.                         close $fp
  25.                         return;
  26.                 }

  27.                 set f1 [lindex $fields 0]
  28.                 set f2 [lindex $fields 1]
  29.                 set f3 [lindex $fields 2]
  30.                 set word $f1$f2
  31.                 incr count($word)
  32.                 set [set word]($line) 0

  33.                 if {! [info exists min($word)]} { set min($word) $f3 }
  34.                 if {! [info exists max($word)]} { set max($word) $f3 }
  35.                 if {$f3 < $min($word)} { set mix($word) $f3 }
  36.                 if {$f3 > $max($word)} { set max($word) $f3 }
  37.         }

  38.         close $fp
  39.         foreach word [array names count] {
  40.                 if {$count($word) > 1 && $max($word) - $min($word) < 10} {
  41.                         foreach line [array names $word] {
  42.                                 .t insert end "$line\n"
  43.                         }
  44.                 }
  45.         }
  46. }
复制代码

filter.JPG (12.36 KB, 下载次数: 55)

filter.JPG

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
10 [报告]
发表于 2010-08-06 09:08 |只看该作者
就是说每一个数都要和其他数做一下减法,如果不行,俩数一并作废。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP