Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to make a list like this:

7785237_770x770_de3b540dc13ed50023d17854513b40aa07e50a6a
732308_770x770_ec5c344c0114011a5306b31142ff9b001813f6d6
7430796_800x800_ec0f2e614e2dc460fca7e626d83073c827dc9130
7431018_800x800_7caa40b85c21485c64f2ad509a0d9cc1ed3ba526

So to explain: First block before the first "_" is just a number between 0 and 9500000 - second block varies between two variables: "770x770" and "800x800"
Last block is a 40 character long HEX block.

So what I want to do, is to generate all possible combinations of these, and combine it into one line.

How do I do this? Don't know if it can be done in BASH, or it should be done in perl/something similar.

share|improve this question
3  
all possible combinations of these you mean all possible combinations of 16**40*9500000*2 so 27768531109287155445870011821609377373462718316544000000 lines? –  neurino May 12 '12 at 23:30
4  
You cannot generate a file containing 9500001*2*16^40 lines. That file would be something like a trillion (US) times the total size of all hard disks in the world. What are you trying to do? A 40-digit hex string looks like a SHA-1 hash; this kind of hash is designed so that you cannot find the right one unless you know what it's the hash of. If you're trying a brute-force search on an image server, forget it; you can't do it, by design. –  Gilles May 12 '12 at 23:46
2  
The FAQ says: "You should only ask practical, answerable questions based on actual problems that you face." –  Mikel May 12 '12 at 23:53
3  
@FrederikNielsen If the ability to reasonably complete your task also implies the ability to brute-force 128-bit symmetric encryption and 160-bit hashes, then no I would not call it practical. If you are or ever become a pointy-haired boss, I'd hate to be one of your employees ... :P –  jw013 May 13 '12 at 0:01
2  
@FrederikNielsen - Yeah, don't do that. –  Chris Down May 13 '12 at 5:48
show 8 more comments

closed as not a real question by Mikel, jw013, Renan, Ulrich Dangel, jasonwryan Aug 18 '12 at 20:37

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 2 down vote accepted

I guess bash cannot handle those amounts and in case it could you'd get old before it sorts it out.

Python itertools can help you creating and assembling all combinations.

I suggest Python and not perl as this is more a math task rather than a text manipulation one.

#!/usr/bin/env python

from itertools import combinations_with_replacement

for x in combinations_with_replacement('0123456789abcdef', 40):
    h = ''.join(x)
    for y in xrange(9500001):
        for r in ("770x770", "800x800"):
            print "{0}_{1}_{2}".format(y, r, h)

Of course Python is way slower than C so don't expect best performances. On the other side don't expect to get the same result in C with only 5 lines of code.

share|improve this answer
    
Looks good Neurino. Now I just gotta figure out how I get the itertools to work on my centos box.. –  Frederik Nielsen May 12 '12 at 23:57
    
python is installed by default on most linux distributions, I think centOS does too. Anyway given it has no practical applications you may not want to save results to a file but simply create a function and let it yield instead of print results. –  neurino May 13 '12 at 0:04
    
Yeah sounds about right, but centos comes with an old python as far as i can see. So trying to compile a newer one now. Anyhow, thanks for the piece of code :) –  Frederik Nielsen May 13 '12 at 0:10
    
I get a syntax error on line 9, at the last " - says Invalid Syntax.. Is it my box thats acting strange, or is there something else wrong? –  Frederik Nielsen May 13 '12 at 0:15
    
Works here with copy & paste. –  jippie May 13 '12 at 7:57
show 1 more comment

protected by TAFKA 'goldilocks' Mar 9 at 4:22

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.