Transposing string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Transposing string
# 1  
Old 02-13-2008
Transposing string

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
# 2  
Old 02-13-2008
This sounds a lot like homework. The forum explicitly bans homework.
# 3  
Old 02-13-2008
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
# 4  
Old 02-13-2008
Quote:
Originally Posted by 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

Code:
# 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
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Transposing a file

Hi Guys, I have file containing this kind of format below: ======== MOBILITY EVENT (G): ATTACH REJECT ========= Time : <date_time> Node : <node> GMM Cause : <code> Details : <details> Attach : <attach type> IMSI : <imsi> PTMSI : <ptmsi> RA New : <ra new> RA... (9 Replies)
Discussion started by: rymnd_12345
9 Replies

2. Shell Programming and Scripting

Transposing text using AWK

Well I thought that this would be a fairly straight forward operation but perhaps I'm complicating it more in my mind. I have a simple data.txt file containing candidate information in the following format: "ANTONIA ROJAS SALES" "Feminino" "13/06/1954" "Casado(a)" "Brasileira... (6 Replies)
Discussion started by: daveyabe
6 Replies

3. Shell Programming and Scripting

awk, string as record separator, transposing rows into columns

I'm working on a different stage of a project that someone helped me address elsewhere in these threads. The .docs I'm cycling through look roughly like this: 1 of 26 DOCUMENTS Copyright 2010 The Age Company Limited All Rights Reserved The Age (Melbourne, Australia) November 27, 2010... (9 Replies)
Discussion started by: spindoctor
9 Replies

4. Shell Programming and Scripting

Transposing rows into columns

I have a file like the one given below P1|V1|V2 P1|V1|V3 P1V1|V2 P2|V1|V4 P2|V2|V6 P2|V1|V4 I want it convert to P1|V1|V2|V2|V3 P2|V1|V4|V2|V6 2nd and 3rd column should be considered as together and so the tird row is duplicate Any ideas? (3 Replies)
Discussion started by: prasperl
3 Replies

5. Shell Programming and Scripting

Transposing a file

Hi All, I have a input file say FILEA. FILEA -------- empid1 sal1 location1 manager1 empid2 sal2 location2 manager2 empid3 sal3 location3 manager3 . . . (3 Replies)
Discussion started by: 46019
3 Replies

6. Shell Programming and Scripting

Transposing a file

i have a file as: 1 2 3 4 5 i want output as : 1 2 3 4 5 can anybody help on this?? (14 Replies)
Discussion started by: vikas_kesarwani
14 Replies

7. UNIX Desktop Questions & Answers

More than transposing!

Hi everyone, I have a poblem like that: I have a file which includes data looks like: 0.65214 0.3597 1.0 0.65244 0.3502 1.0 0.65273 0.3553 1.0 0.65305 0.3544 1.0 0.65327 0.3505 1.0 0.65359 0.3516 1.0 0.65578 0.6464 1.0 0.65605 0.6453 1.0 0.65633 0.6437 1.0 0.65660 0.6488 1.0... (3 Replies)
Discussion started by: bulash
3 Replies

8. Shell Programming and Scripting

Another transposing issue

Hello I need to sort a file with data such as so it breaks on column 1 and all the data in column 2 is sorted into rows with a unique column 1: 1 5 1 6 1 7 2 3 2 4 3 7 3 0 3 9 So it comes out as: 1 5 6 7 2 3 4 3 7 0 9 I've tried many iterations of nawk but can't get it... (14 Replies)
Discussion started by: stevesmith
14 Replies

9. Shell Programming and Scripting

file transposing

Hello, Is there a way to transpose a file in shell scripting? For instance, from a1 a2 a3 a4 a5 a6 a7 .... b1 b2 b3 b4 b5 b6 b7 .... c1 c2 c3 c4 c5 c6 c7 .... d1 d2 d3 d4 d5 d6 d7 ... ... ... ... to a1 b1 c1 d1 .... a2 b2 c2 d2 .... a3 b3 c3 d3 .... a4 b3 c3 d4 .... ... ... (24 Replies)
Discussion started by: mskcc
24 Replies

10. Shell Programming and Scripting

transposing letters

Hi, I've written a shell function in bash that reads letters into an array, then outputs them in one column with: for n in "${array}"; do echo $n done I was wondering if anyone knew how i would transpose the letters that are output by the for loop. Right now my output is: aabbcc... (4 Replies)
Discussion started by: myscsa2004
4 Replies
Login or Register to Ask a Question