I want to make a list like this:


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.

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.

  • 4
    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

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.

  • 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

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