Generate a string of alphanumeric characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Generate a string of alphanumeric characters
# 1  
Old 03-20-2019
Generate a string of alphanumeric characters

Hi,
I want a script of a code that will allow me to generate all possible combinations of alphanumberica characters of length 12 such that each string will contain numbers and either small or capital letters.
For example a string may look like this: 123AB45cd678.
# 2  
Old 03-20-2019
I think you might want to rethink your post. Just using base36 numbers in bash to answer your post:
Code:
$ echo $((36#zzzzzzzzzzzz))
4738381338321616895

That is the largest 12 digit number in base36 - the gigantic number. It could easily take a desktop computer long time to count that high.
Every combination of base 36 number taken 12 at a time is much larger than the stupidly large number above.

I'm positive you need to tell us what you are trying to do, I've answered the question of how to print a decimal version base36 number, which is not what you asked. Mostly for completeness.
Code:
echo $((base#number))

Can you please tell us your requirement - example: generate 12 character passwords for linux.

Last edited by jim mcnamara; 03-20-2019 at 11:08 PM..
# 3  
Old 03-21-2019
Hi,
the number of all combinations from your condition is equal to 2.6543489742975863e+21
Where will you put everything? ...even if you will write in C... Smilie
set the condition exactly

Last edited by nezabudka; 03-21-2019 at 02:34 AM..
# 4  
Old 03-21-2019
@jim mcnamara & @nezabudka: Out of sheer curiosity - how did you derive those numbers? For me, the ASCII alphabet has 26 characters; upper case and lower case plus 10 digits makes that 62. 62^12=3,23e+21 - am I wrong?
This User Gave Thanks to RudiC For This Post:
# 5  
Old 03-21-2019
Yes. I was mistaken I considered 61. I need to learn the alphabet Smilie

Last edited by nezabudka; 03-21-2019 at 06:54 AM..
# 6  
Old 03-21-2019
I just used bash to transform zzzzzzzzzzz, the highest value for 12 digits of base36, into decimal. It may not even be correct. Sorry for the confusion.

The idea of the OP's post seemed to be wildly unattainable with modern desktop hardware and/or required specialty software. Plus, where do you store the output? So I went with a quick version, since I do not have any bignum software on this box.

And base62 is correct, my explanation was for base64. I really was not clear.

Using {@,_} for "positions" 63 and 64 is bash behavior, I believe.
# 7  
Old 03-21-2019
Quote:
Originally Posted by jim mcnamara
I just used bash to transform zzzzzzzzzzz, the highest value for 12 digits of base36, into decimal. It may not even be correct. Sorry for the confusion.

The idea of the OP's post seemed to be wildly unattainable with modern desktop hardware and/or required specialty software. Plus, where do you store the output? So I went with a quick version, since I do not have any bignum software on this box.

And base62 is correct, my explanation was for base64. I really was not clear.

Using {@,_} for "positions" 63 and 64 is bash behavior, I believe.
Note that there are only eleven z's in the string in red above; not twelve.

I thought most systems these days came with bc and/or dc.
Code:
$ echo '62 12^p' | dc
3226266762397899821056
$ echo '62^12' | bc
3226266762397899821056
$ 

Unfortunately, standard versions of bc are only required to handle input bases between 2 and 16 (inclusive) and dc isn't in the standards (but frequently has the same limits) so calculation in base 36 or base 62 aren't handled directly by these utilities. (On many systems, bc is implemented as a front-end to dc.) But from the above bc and dc output, I can say that 1000000000000 (base 62) (that is a digit 1 followed by twelve digit 0s) is 3226266762397899821056 (base 10).
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need to compare numbers in alphanumeric string

Hi, I will be having file names like below, 1420SP1.01804 1420SP1.01805D 1420SP1.01805 1420SP1.01806D 1420SP1.01806 1420SP1.01901D 1420SP1.01901 1420SP1.01902D 1420SP1.01902 1420SP1.01903D 1420SP1.01903 1420SP1.01904 1420SP1.01905 From this, I need to list file names which is... (3 Replies)
Discussion started by: Sumanthsv
3 Replies

2. Shell Programming and Scripting

how to insert space in alphanumeric string

Hi everyone, I want help to insert space between digits and letters in a alphanumeric string. INPUT TRY234TER PHY1TYR EXPECTED OUTPUT TRY 234 TER PHY 1 TYR The lines always begin with the letters and the alphabets will be a three letter combination before and after the number. The... (2 Replies)
Discussion started by: kaav06
2 Replies

3. Shell Programming and Scripting

parse a mixed alphanumeric string from within a string

Hi, I would like to be able to parse out a substring matching a basic pattern, which is a character followed by 3 or 4 digits (for example S1234 out of a larger string). The main string would just be a filename, like Thisis__the FileName_S1234_ToParse.txt. The filename isn't fixed, but the... (2 Replies)
Discussion started by: keaneMB
2 Replies

4. Shell Programming and Scripting

Sed or trim to remove non alphanumeric and alpha characters?

Hi All, I am new to Unix and trying to run some scripting on a linux box. I am trying to remove the non alphanumeric characters and alpha characters from the following line. <measResults>883250 869.898 86432.4 809875.22 804609 60023 59715 </measResults> Desired output is: 883250... (6 Replies)
Discussion started by: jackma
6 Replies

5. Shell Programming and Scripting

get rid of non-alphanumeric characters

Hi! Could anyone so kindly help me a code to eliminate from a txt file, obtained by collecting and merge several web-page, every word (string) containing non alphabetical, numeric and punctuation character (i.e NON a-zA-Z0-9, underscore and punctuation mark)? Thanks a lot for the help to... (5 Replies)
Discussion started by: mjomba
5 Replies

6. Shell Programming and Scripting

Sorting with non- and alphanumeric characters

Hi guys, I'm new to this forum and I'm not a UNIX expert. I can't figure out this certain problem i'm having: I need to sort some words, some of the words are annotations (enclosed within < and >). I need to have them sorted alphabetically with all non-alphanumeric characters up front. For... (2 Replies)
Discussion started by: fed.m.ang
2 Replies

7. Shell Programming and Scripting

ksh - test if string contains alphanumeric...

Okay I will let users input spaces as well :) I am having a mental block. I have done a couple of searches but havent found anything that I understand (the likes of :alpha: and awk). Basically I want to give the user an option to enter some text which will go down as a field within a flat... (3 Replies)
Discussion started by: tugger
3 Replies

8. Shell Programming and Scripting

With Regex Spliting the string into Alphanumeric and Numeric part

Hi there With shell script I'm trying to split the string into two parts. One is alphanumeric part, the other one is a numeric part. dummy_postcode_1 = 'SL1' --> res_alpha = 'SL' and res_numeric = '1' dummy_postcode_2 = 'S053' --> res_alpha = 'S' and res_numeric = '053' ... (1 Reply)
Discussion started by: ozgurgul
1 Replies

9. UNIX for Dummies Questions & Answers

AlphaNumeric String Operations

Hi :) I am writing a ksh I have a string of general format A12B3456CD78 the string is of variable length the string always ends with numbers (here it is 78.. it can be any number of digits may be 789 or just 7) before these ending numbers are alphabets (here it is CD can even be... (3 Replies)
Discussion started by: lakshmikanth
3 Replies

10. Shell Programming and Scripting

matching alphanumeric string

how to match an alphanumeric string like the following. i have to do like the following. if the input line is the data is {clock_91b} i have to replace that with the string was ("clock_91b") i tried like $line =~ s/the data is\s+\{(+)\}/the string was \(\"$1\"\)/ which... (4 Replies)
Discussion started by: sskb
4 Replies
Login or Register to Ask a Question