【问题标题】:script to compare two large 900 x 900 comma delimited files比较两个大的 900 x 900 逗号分隔文件的脚本
【发布时间】:2015-03-25 11:51:32
【问题描述】:

我尝试过 awk,但无法在两个文件上一次为每个单元格 1 执行差异。我已经尝试过 awk 但无法在两个文件上一次为每个单元格 1 执行差异。我尝试过 awk,但无法在两个文件上一次对每个单元格 1 执行差异。

【问题讨论】:

  • edit 向我们提供您输入的示例(示例不一定必须是 900x900)以及您的目标是什么。如果您已经尝试过,也请包括在内。

标签: linux bash awk


【解决方案1】:

如果您只是想要一个粗略的答案,可能最简单的方法是:

tr , \\n file1 > /tmp/output
tr , \\n file2 | diff - /tmp/output

这会将每个文件转换为一列并运行 diff。您可以计算与输出的行号不同的单元格。

【讨论】:

    【解决方案2】:

    最简单的 awk 方法,无需考虑字段内的换行符、引号等。

    打印一样

    awk 'BEGIN{RS=",|"RS}a[FNR]==$0;{a[NR]=$0}' file{,2}
    

    打印差异

    awk 'BEGIN{RS=",|"RS}FNR!=NR&&a[FNR]!=$0;{a[NR]=$0}' file{,2}
    

    打印相同的不同

    awk 'BEGIN{RS=",|"RS}FNR!=NR{print "cell"FNR (a[FNR]==$0?"":" not")" the same"}{a[NR]=$0}' file{,2}
    

    输入

    文件

    1,2,3,4,5  
    6,7,8,9,10  
    11,12,13,14,15  
    

    文件2

    1,2,3,4,5  
    2,7,1,9,12  
    1,1,1,1,12  
    

    输出

    一样

    1
    2
    3
    4
    5
    7
    9
    

    不同

    2
    1
    12
    1
    1
    1
    1
    12
    

    相同的不同

    cell1 the same
    cell2 the same
    cell3 the same
    cell4 the same
    cell5 the same
    cell6 not the same
    cell7 the same
    cell8 not the same
    cell9 the same
    cell10 not the same
    cell11 not the same
    cell12 not the same
    cell13 not the same
    cell14 not the same
    cell15 not the same
    

    【讨论】:

      猜你喜欢
      • 2013-07-02
      • 1970-01-01
      • 1970-01-01
      • 2010-12-09
      • 1970-01-01
      • 2012-10-29
      • 2020-04-04
      • 1970-01-01
      • 2023-03-16
      相关资源
      最近更新 更多