# Transposing string

**URL:** <https://community.unix.com/t/transposing-string/185444>\
**Category:** Shell Programming and Scripting\
**Created:** [February 13, 2008, 4:15pm UTC](https://community.unix.com/t/transposing-string/185444 "2008-02-13T16:15:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![unibboy](https://community.unix.com/letter_avatar/unibboy/32/5_5575768a8748004e209b776fc1b2916d.png) [@unibboy](https://community.unix.com/u/unibboy)\
**Post date:** [February 13, 2008, 4:15pm UTC](https://community.unix.com/t/transposing-string/185444/1 "2008-02-13T16:15:50Z")

</div>

Hello guys,

can some please give driection as to how to archieve this big issue i am having:

I a random number that has been generated and wants the user to guess it, let me illustrate this:

say the random i hve generated is 'nice'

- i then hide it from the user and display it in ----  
-but now if the use enter 'n' because it is in the random word, i would then display to them n---  
and so until they get all the letters

i have used a while loop, but i seem to be loosing previously guessed letters

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [February 13, 2008, 4:24pm UTC](https://community.unix.com/t/transposing-string/185444/2 "2008-02-13T16:24:04Z")

</div>

This sounds a lot like homework. The forum explicitly bans homework.

---

<div class="post-metadata">

**Author:** ![unibboy](https://community.unix.com/letter_avatar/unibboy/32/5_5575768a8748004e209b776fc1b2916d.png) [@unibboy](https://community.unix.com/u/unibboy)\
**Post date:** [February 13, 2008, 4:26pm UTC](https://community.unix.com/t/transposing-string/185444/3 "2008-02-13T16:26:53Z")

</div>

my apologies, its not an home, its an element of a project i am working, though its work based. I was just asking for a guidance

---

<div class="post-metadata">

**Author:** ![otheus](https://community.unix.com/user_avatar/community.unix.com/otheus/32/505_2.png) [@otheus](https://community.unix.com/u/otheus)\
**Post date:** [February 13, 2008, 5:12pm UTC](https://community.unix.com/t/transposing-string/185444/4 "2008-02-13T17:12:25Z")

</div>

> [@unibboy](#):
>
> Hello guys,
> 
> -but now if the use enter 'n' because it is in the random word, i would then display to them n---  
> and so until they get all the letters
> 
> i have used a while loop, but i seem to be loosing previously guessed letters
> 
> I just want guidance

```plaintext
# pseudo code

random_word=`generate_random_word`
guessed_letters=`echo $random_word | sed -e 's/./-/gp'`
guesses=0
max_guesses=26

while ( $random_word != $guessed_letters && $guesses < $max_guesses ) {
  # If the input can be found in $random_word, 
  # replace the same position in $guessed_letters with that input. 
  # 
  # ++$guesses

  print $guessed_letters
}

```
