Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3804200
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:28:52+00:00 2026-05-19T14:28:52+00:00

I have about 30 500MB files, one word per line. I have a script

  • 0

I have about 30 500MB files, one word per line. I have a script that does this, in pseudo-bash:

for i in *; do
    echo "" > everythingButI
    for j in *-except-$i; do
        cat $j >> everythingButI
        sort everythingButI | uniq > tmp
        mv tmp everythingButI
    done
    comm $i everythingButI -2 -3 > uniqueInI

    percentUnique=$(wc -l uniqueInI) / $(wc -l $i) * 100
    echo "$i is $percentUnique% Unique"
done

It computes the ‘uniqueness’ of each file (the files are already sorted and unique within each file).

So if I had files:

file1    file2   file3
a        b       1
c        c       c
d        e       e
f        g
         h

file1 would be 75% unique (because 1/4 of it’s lines are found in another file), file2 would be 60% unique, and file3 would be 33.33% unique. But make it 30 files at 500MB a pop, and it takes a bit to run.

I’d like to write a python script that does this much, much faster, but I’m wondering what the fastest algorithm for this would actually be. (I only have 2GB of RAM on the PC also.)

Anyone have opinions about algorithms, or know of a faster way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T14:28:53+00:00Added an answer on May 19, 2026 at 2:28 pm

    EDIT: Since each of the inputs are already internally sorted and deduplicated, you actually need an n-way merge for this, and the hash-building exercise in the previous version of this post is rather pointless.

    The n-way merge is kind of intricate if you’re not careful. Basically, it works something like this:

    • Read in the first line of each file, and initialize its unique lines counter and total lines counter to 0.
    • Do this loop body:
      • Find the least value among the lines read.
      • If that value is not the same as the one from any of the other files, increment that file’s unique lines counter.
      • For each file, if the least value equals the last value read, read in the next line and increment that file’s total lines counter. If you hit end of file, you’re done with that file: remove it from further consideration.
    • Loop until you have no files left under consideration. At that point, you should have an accurate unique lines counter and total lines counter for each file. Percentages are then a simple matter of multiplication and division.

    I’ve left out the use of a priority queue that’s in the full form of the merge algorithm; that only becomes significant if you have a large enough number of input files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have about 200 Excel files that are in standard Excel 2003 format. I
I have about 10million values that I need to put in some type of
I have about 10 drop down list controls that get populated. Instead of copying/pasting
I have about 100 Word documents which include transliteration of foreign names. The author
I have an ASP.NET website that will hit about 2gb physical memory used within
I have this application with which I would like to store about 50MB of
for that past couple of weeks I have been creating generic script that is
I have about 20 different images that I want to fade in and out
I am unable to find out more about this default parameter that I ran
How does one programmatically determine a Chrome user's maximum temporary internet files cache size?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.