The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts 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-10-2007 10:58 PM
Question about GREP Adriel UNIX for Dummies Questions & Answers 16 03-22-2007 05:03 AM
Another grep question kingdbag UNIX for Dummies Questions & Answers 6 10-26-2006 10:56 PM
grep & sed question der Kopf Shell Programming and Scripting 1 11-22-2004 01:49 AM
Grep question eloquent99 UNIX for Dummies Questions & Answers 4 02-20-2003 07:49 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-18-2008
Registered User
 

Join Date: Mar 2008
Location: England
Posts: 3
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 02:59 AM. Reason: added more text
Reply With Quote
Forum Sponsor
  #2  
Old 03-18-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
Are you trying to do steganography? Your example isn't clear to me. grep is not normally used to add something that isn't there already. It just searches, sed is used to change data.
Reply With Quote
  #3  
Old 03-18-2008
Registered User
 

Join Date: Mar 2008
Location: England
Posts: 3
Quote:
Originally Posted by jim mcnamara View Post
Are you trying to do steganography? Your example isn't clear to me. grep is not normally used to add something that isn't there already. It just searches, sed is used to change data.
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.
Reply With Quote
  #4  
Old 03-18-2008
era
Guest
 

Posts: n/a
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.
Reply With Quote
  #5  
Old 03-18-2008
Registered User
 

Join Date: Mar 2008
Location: England
Posts: 3
Quote:
Originally Posted by era View Post
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.
Yeah thats right something like hangman do you have any examples for me to see what the script would look like
Reply With Quote
  #6  
Old 03-18-2008
joeyg's Avatar
Moderator
 

Join Date: Dec 2007
Location: Home of world champion Boston Celtics
Posts: 982
Cool Similar question handled before

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"
Reply With Quote
  #7  
Old 03-18-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:00 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0