I have to write a UNIX script (KSH) to create a 6 letter abbreviation from a given string. The string will have alphabets and underscores only.
e.g. abc_pst_xyz is our string and I have to create an abbreviation which will look like 'abpsxy' or 'abcpyz' etc.
Now comes the tricky part. I have to make sure that out of the given set of strings no two strings have the same abbreviation.
Basically, I need to search a particular directory and see if such an abbreviation already exists. If it does then, I have to recreate a new set of 6 letter abbreviation from the string.
Please help me with this script. Also, help me understand the logic to generate or select random characters from a string.
Thanks. Replacing nawk by awk worked perfectly.
Now my other question is:
In the example you have stated, we get all the possible set of combinations of 3 letter string from 'abcd'.
But if I replace 'abcd' with 'abc_d' then I get set of string which have '' underscore as well. However, I want that whatever be the parent string (including '"), the generated abbreviation should not have an underscore.
How do I eliminate the occurrence of underscore.
Also, I understood the functions that you have created but what does the following line do:
awk -v Abbrev_Len=${2:-6}
Can you please provide me a link where I can get information about awk and how to use it in UNIX scripts?