![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Grep question. | saurabhsinha23 | UNIX for Dummies Questions & Answers | 3 | 12-11-2007 01:58 AM |
| Question about GREP | Adriel | UNIX for Dummies Questions & Answers | 16 | 03-22-2007 08:03 AM |
| Another grep question | kingdbag | UNIX for Dummies Questions & Answers | 6 | 10-27-2006 01:56 AM |
| grep & sed question | der Kopf | Shell Programming and Scripting | 1 | 11-22-2004 04:49 AM |
| Grep question | eloquent99 | UNIX for Dummies Questions & Answers | 4 | 02-20-2003 10:49 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Question of grep
As i understand the filter process of grep i was wondering, is it possible to to have a hidden word in a file(eg ------) and then use the grep filter to find a specific letter in that word which you can then replace with the letter in that word (eg ---a--) if it is please show me an example if it isnt which is the best form to use to change and display what i am trying to do
Last edited by ZAXTHEGREAT; 03-18-2008 at 05:59 AM.. Reason: added more text |
|
||||
|
The idea is to have some words within another file and then use a random select to get a word from that file and then generate as ----- so it is hidden from the user. From that they have to guess the letter and with the simple input they give this would then search the word for the letter and then replace it with the users inputted letter so ----a-- as an eg. The question is can grep be used if so or if not how to do this.
|
|
||||
|
A Hangman game? Just grep is not sufficient, no. Like Jim already told you, grep can find lines in a file which match a particular pattern, but it just prints them, nothing more. In particular, it doesn't replace characters with other characters; nor does it have loops (other than the input loop for reading in the file, one line at a time, and print those lines which match the specified pattern. If you are really clever you could perhaps use that to drive something ...)
Google for "Hangman source code" or visit the "99 bottles of beer" site. |
|
||||
|
Quote:
|
|
|||||
|
See the followint link:
Matching string Code:
WORD="nasty"
cnt=0
known="n"
while [ $known = "n" ]
do
echo -e "Input a char: \c"
read CHAR
CHARS="${CHARS}${CHAR}"
((cnt = cnt + 1))
disp=$(echo "$WORD" | sed "s/[^${CHARS}]/-/g")
echo $disp
if [ $WORD = $disp ]
then
known="y"
fi
done
echo $cnt" guesses"
|
|
||||
|
Yes examples: google for hangman source code
Our own zazzybob has a nice one on his site: [ z a z z y b o b . c o m ] $HOME/games/shangman |
| Sponsored Links | ||
|
|