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 509435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:00:38+00:00 2026-05-13T07:00:38+00:00

I need the MD5 sums of 3 million strings or so in a bash

  • 0

I need the MD5 sums of 3 million strings or so in a bash script on ubuntu. 3 million strings -> 3 million MD5 hashes. The trivial implementation takes about 0.005sec per string. That’s over 4 hours. What faster alternatives exist? Is there a way to pump groups of strings into md5sum?

#time md5sum running 100 times on short strings
#each iteration is ~0.494s/100 = 0.005s
time (for i in {0..99}; do md5sum <(echo $i); done) > /dev/null

real    0m0.494s
user    0m0.120s
sys     0m0.356s

A good solution will include a bash/Perl script that takes a list of strings from stdin and outputs a list of their MD5 hashes.

  • 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-13T07:00:38+00:00Added an answer on May 13, 2026 at 7:00 am

    It’s not hard to do in C (or Perl or Python) using any of the many md5 implementations — at its heart md5 is a hash function that goes from a character vector to a character vector.

    So just write a outer program that reads your 3 million strings, and then feed them one by one to the md5 implementation of your choice. That way you have one program startup rather than 3 million, and that alone will save you time.

    FWIW in one project I used the md5 implementation (in C) by Christophe Devine, there is OpenSSL’s as well and I am sure CPAN will have a number of them for Perl too.

    Edit: Ok, couldn’t resist. The md5 implementation I mentioned is e.g. inside this small tarball. Take the file md5.c and replace the (#ifdef’ed out) main() at the bottom with this

    int main( int argc, char *argv[] ) {
        FILE *f;
        int j;
        md5_context ctx;
        unsigned char buf[1000];
        unsigned char md5sum[16];
    
        if( ! ( f = fopen( argv[1], "rb" ) ) ) {
            perror( "fopen" );
            return( 1 );
        }
    
        while( fscanf(f, "%s", buf) == 1 ) {
            md5_starts( &ctx );
            md5_update( &ctx, buf, (uint32) strlen((char*)buf) );
            md5_finish( &ctx, md5sum );
    
            for( j = 0; j < 16; j++ ) {
                printf( "%02x", md5sum[j] );
            }
            printf( " <- %s\n", buf );
        }
        return( 0 );
    }
    

    build a simple standalone program as e.g. in

    /tmp$ gcc -Wall -O3 -o simple_md5 simple_md5.c
    

    and then you get this:

    # first, generate 300,000 numbers in a file (using 'little r', an R variant)
    /tmp$ r -e'for (i in 1:300000) cat(i,"\n")' > foo.txt
    
    # illustrate the output
    /tmp$ ./simple_md5 foo.txt | head
    c4ca4238a0b923820dcc509a6f75849b <- 1
    c81e728d9d4c2f636f067f89cc14862c <- 2
    eccbc87e4b5ce2fe28308fd9f2a7baf3 <- 3
    a87ff679a2f3e71d9181a67b7542122c <- 4
    e4da3b7fbbce2345d7772b0674a318d5 <- 5
    1679091c5a880faf6fb5e6087eb1b2dc <- 6
    8f14e45fceea167a5a36dedd4bea2543 <- 7
    c9f0f895fb98ab9159f51fd0297e236d <- 8
    45c48cce2e2d7fbdea1afc51c7c6ad26 <- 9
    d3d9446802a44259755d38e6d163e820 <- 10
    
    # let the program rip over it, suppressing stdout
    /tmp$ time (./simple_md5 foo.txt > /dev/null)
    
    real    0m1.023s
    user    0m1.008s
    sys     0m0.012s
    /tmp$
    

    So that’s about a second for 300,000 (short) strings.

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

Sidebar

Related Questions

I need to write a bash script that scans directories in current directory and
I need to generate md5 hash for ~40 millions strings with salt (~20 symbols),
Please I need help getting the exact md5 value of this python script in
for a small project I need identical md5 hashes for both JS and PHP.
I need to hash (MD5) all the password in our Sql Server 2000 database.
Hi In My application I need to calcluate the md5 Hash Value for a
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
Need MD5 hash for an in memory System.Drawing.Image
I need to examine the output of a certain script 1000s of times on
I have used microsoft system.security.cryptography to make md5 in c# application but I need

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.