代码之家  ›  专栏  ›  技术社区  ›  vehomzzz

确定过时数据

  •  0
  • vehomzzz  · 技术社区  · 14 年前

    12:04:21  .3
    12:10:21  1.3
    12:13:21  1.4
    12:14:21  1.3
    ..and so on
    

    我想在第二列中找到10个后续时间戳的重复数字,从而找到陈旧性。

    12:04:21  .3
    12:10:21  1.3
    12:14:21  1.3
    12:10:21  1.3
    12:14:21  1.3
    12:12:21  1.3
    12:24:21  1.3
    12:30:21  1.3
    12:44:21  1.3
    12:50:21  1.3
    13:04:21  1.3
    13:24:21  1.7
    

    应该打印

    我想输出过时时间戳范围的开始和结束

    有人能帮我提出来吗?

    你可以用awk,bash

    2 回复  |  直到 14 年前
        1
  •  1
  •   Dennis Williamson    14 年前
    awk 'BEGIN { count = 1} { if ( $2 == prev ) { ++count; if ( ! start ) {start = prevtime} end = $1 } 
           else if ( count >= 10 ) { print start, end, prev; count = 1; start = "" }
           else { start = "" }; 
           prev = $2; prevtime = $1 }' file.dat
    

    编辑2:

    发现并修复了另一个错误。

        2
  •  0
  •   Hai Vu    14 年前

    这是我的版本,更详细:

    # This function prints out the summary only when count >= 10
    function print_summary(count, first, last, value) {
        if (count >= 10) {
            printf "%s through %s %s (%d)\n", first, last, last_value, count
        }
    }
    
    $2 == last_value {
        last_occurance = $1
        count++
    }
    
    $2 != last_value {
        print_summary(count, first_occurance, last_occurance, last_value)
        first_occurance = $1
        last_value = $2
        count = 1
    }
    
    END { 
        print_summary(count, first_occurance, last_occurance, last_value)
    }