1 million recorded text files, remove the top 10 duplicates.

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

Seeking Ideas


Reply to discussion (solution)

Import into the table, and then use SQL statistics to not know if it is feasible. You can try it.

Import into the table, and then use SQL statistics to not know if it is feasible. You can try it.


This is certainly possible, but it should not be the solution that the person who asked the question wanted. Want to use PHP processing or algorithms

Explode//Read split array
array_count_values//count repetitions
arsort//sort, get results

Can be the text block processing, record the results, estimated one-time reading, memory also can't eat ...

Can be the text block processing, record the results, estimated one-time reading, memory also can't eat ...


Well, your way of leaning, can you elaborate on that?

$fp = fopen (' file ', ' R '), while ($buf = fgets ($fp)) {  $res [$buf]++;} Fclose ($FP); Arsort ($res); $res = Array_keys (array_slice ($res, 0, ten));p Rint_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, ten));p Rint_r ($res);

Bulk INSERT into the database and then use the SQL Statement's group BY and order by implementations

  • Related Article

    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.