LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Anybody with a word scrambling script ? (http://www.linuxquestions.org/questions/programming-9/anybody-with-a-word-scrambling-script-561758/)

TRJ 06-14-2007 07:30 AM

Anybody with a word scrambling script ?
 
Hi guys,

I am trying to write a short script that allows me to read in a word from an input file. I then want to change the character at different positions into various other characters like:

ABCDEFGH #read from input file
#now change character 2 into all other possible
AACDEFGH #output 1
ACCDEFGH #output 2
ADCDEFGH #output 3
etc.

... and then export this new word as a new file (or read it into an executable script). Has anybody a good idea how I could do that. I need to define position as well as the possible characters to change to and write it into a file named with the change.

I am struggeling ... Thanks for your help.

Tom :scratch:

wjevans_7d1@yahoo.co 06-15-2007 12:42 AM

What part of this have you written so far? May we see it?

atulsvasu 06-19-2007 12:39 PM

Hmm.. I don't intend to code, it is very easy..

for(i)
if(i!=1) str[1] = str[i]

cfaj 06-19-2007 01:56 PM

Quote:

Originally Posted by TRJ
Hi guys,

I am trying to write a short script that allows me to read in a word from an input file. I then want to change the character at different positions into various other characters like:

ABCDEFGH #read from input file
#now change character 2 into all other possible
AACDEFGH #output 1
ACCDEFGH #output 2
ADCDEFGH #output 3
etc.

... and then export this new word as a new file (or read it into an executable script). Has anybody a good idea how I could do that. I need to define position as well as the possible characters to change to and write it into a file named with the change.


This should get you started:

Code:

letters="A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
read word
right=${word#??}
left=${word%?"$right"}
for l in $letters
do
  printf "%s\n" "$left$l$right"
done


TRJ 06-20-2007 02:40 AM

Cheers guys, I think that will sort me out for the start. I have started to play around with my scripting skills (i.e. not very much so far) and it runs for a start. Not quite what intended, but at least I am on my way. T.

bigearsbilly 06-20-2007 08:32 AM

are you using bash?
you can do stuff like this...

Code:

$ echo here,{A,B,C,D,E},there
here,A,there here,B,there here,C,there here,D,there here,E,there



All times are GMT -5. The time now is 08:36 AM.