The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-18-2008
ZAXTHEGREAT ZAXTHEGREAT is offline
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 05:59 AM.. Reason: added more text
  #2 (permalink)  
Old 03-18-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
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.
  #3 (permalink)  
Old 03-18-2008
ZAXTHEGREAT ZAXTHEGREAT is offline
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.
  #4 (permalink)  
Old 03-18-2008
era
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
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.
  #5 (permalink)  
Old 03-18-2008
ZAXTHEGREAT ZAXTHEGREAT is offline
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
  #6 (permalink)  
Old 03-18-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
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"
  #7 (permalink)  
Old 03-18-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 09:08 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0