# Thread: Bash script. Help with 10 digit number

1. Chocolate-Covered Ubuntu Beans
Join Date
Jan 2009
Location
Denmark
Beans
Hidden!
Distro
Ubuntu 12.04 Precise Pangolin

## Bash script. Help with 10 digit number

Hi guys.

I have a 10 digit number xxxxxx-xxxx, where i would like to calculate the number of different number combinations.
And print each combination in it's full length.

My question is as follows.
What is the most optimal way of doing this in a bash script, when i have the following info

• Digit 1-7 i already know
• Digit 8-9 is a serial number (Unknown digits)
• Digit 10 i know is a even or odd number based on a inpur variable.

Hope it makes sense.
Kind regards.
Last edited by Drenriza; June 12th, 2013 at 09:17 AM.

2. ## Re: Bash script. Help with 10 digit number

If the only digits you don't know are the 7th and 8th, then you have 10x10=100 combinations, and you can generate all the numbers in a loop that counts from 00 to 99:

Code:
```for i in {00..99}
do
printf "xxxxxx-%dxx\n" \$i
done```
Adding the last two digits to this is left as an exercise to the reader, using an inner loop and the brace expansion with increment: {01..99..2} or {00..98..2}
Last edited by ofnuts; June 12th, 2013 at 09:15 AM.

3. Staff Emeritus
Join Date
Apr 2012
Beans
6,947

## Re: Bash script. Help with 10 digit number

or something like

Code:
`oe=3; echo 123456-7{0..9}{0..9}\${oe}`
Code:
```oe=2; echo 123456-7{0..9}{0..9}\${oe} | wc -w
100```
Last edited by steeldriver; June 12th, 2013 at 09:21 AM.

4. ## Re: Bash script. Help with 10 digit number

Hmm. Yes. Even simpler:

123456-7{01-99}{0..8..2} for even
123456-7{01-99}{1..9..2} for odd

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•