1 million minutes of text files, remove the top 10 duplicates

Source: Internet
Author: User
1 million recorded text files, remove the top 10 duplicates.
1.1 million recorded text files, remove the top 10 duplicates.
Sample text:
098
123
234
789
......
234
678
654
123

Seeking Ideas

Share to: more


------Solution--------------------
Import into the table, and then use SQL statistics to not know if it is feasible. You can try it.
------Solution--------------------
Explode//Read split array
array_count_values//count repetitions
arsort//sort, get results


------Solution--------------------
Can be the text block processing, record the results, estimated one-time reading, memory also can't eat ...
------Solution--------------------
$fp = fopen (' file ', ' R ');
while ($buf = fgets ($fp)) {
$res [$buf]++;
}
Fclose ($FP);
Arsort ($res);
$res = Array_keys (array_slice ($res, 0, 10));
Print_r ($res);

When 1 million records are only half the case, there is no difference from the algorithm below
$a = file (' files ');
$res = array_count_values ($a);
Arsort ($res);
$res = Array_keys (array_slice ($res, 0, 10));
Print_r ($res);
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.