【问题标题】:Removing duplicates from a large dataset从大型数据集中删除重复项
【发布时间】:2014-06-30 22:13:50
【问题描述】:

我有一个超过 800000 行的数据集,每个偶数行都是之前奇数行的副本。我想删除重复项。请问有人可以帮忙吗?

【问题讨论】:

  • 到目前为止你有没有尝试过?

标签: duplicates


【解决方案1】:

可以尝试使用它,它使用缓冲读取和写入来逐行读取/写入,每隔一个跳过。 (目前无权使用编译器来解决任何小错误,如果您有任何问题评论,我会编辑,好吗?)

Charset charset = Charset.forName("US-ASCII"); //Change to the right charset
Path toRead = Paths.get("largefile.txt");
Path toWrite = Paths.get("filteredfile.txt");
try (BufferedReader reader = Files.newBufferedReader(toRead, charset)) {
    String line = null;
    int skip=0;
    while ((line = reader.readLine()) != null) {
        if(skip==0)
        {
            skip=1;
            try (BufferedWriter writer = Files.newBufferedWriter(toWrite, charset)) {
                writer.write(line, 0, line.length());
                writer.newLine();
                writer.close();
            } catch (IOException x) {
                System.err.format("IOException: %s%n", x);
            }
        }
        else skip=0;
    }
} catch (IOException x) {
    System.err.format("IOException: %s%n", x);
}

【讨论】:

    【解决方案2】:

    我认为你应该提供更多关于这件事、编程语言等的信息......

    我的猜测是您应该更改查询以避免重复(即使使用“不同”也应该有效)。

    请发布更多信息,以便我们为您提供帮助。

    【讨论】:

      猜你喜欢
      • 2013-08-27
      • 1970-01-01
      • 2017-01-16
      • 2019-05-20
      • 1970-01-01
      • 2021-05-16
      • 2016-05-16
      • 2011-08-08
      • 2020-06-04
      相关资源
      最近更新 更多