View Single Post
Old Apr 6th, 2005, 9:08 AM   #6
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Try this:

#Filename: user_retrieval : Author: L.Pearce
 
function grepfunction
{
 
cat $filename | $gtool $parameter
 
}
 
#:::How does a user type data to be stored in a variable?:::
#-------------------------------------------------------------
echo
echo
echo ":::Retrieval of Information using 'Grep':::"
echo
echo "enter the tool you are using here:"
read gtool
echo "$gtool was the tool you typed"
echo
echo
echo
echo
#:::Similarly, a user can specify a parameter to be stored in a variable:::
#-------------------------------------------------------------------------
echo
echo
echo "enter the parameter you wish to search by:"
read parameter
echo "$parameter was the parameter you typed"
echo
echo
echo
echo
 
#:::And, a user can specify a filename to be stored in a variable:::
#-------------------------------------------------------------------------
echo
echo
echo "Enter file name to be searched"
read filename
if [ -r "$filename" -a -f "$filename" ]
then
clear
 
#:::How can the data stored in that variable be used to search a file?:::
#------------------------------------------------------------------------
#By calling the function "grep function"
 
grepfunction
else
echo "Could not search!"
[jpowers@adsl-065-005-212-144 test]$ more grepit.sh
#Filename: user_retrieval : Author: L.Pearce
 
function grepfunction
{
 
cat $filename | $gtool $parameter 
 
}
 
#:::How does a user type data to be stored in a variable?:::
#-------------------------------------------------------------
echo
echo
echo ":::Retrieval of Information using 'Grep':::"
echo
echo "enter the tool you are using here:"
read gtool
echo "$gtool was the tool you typed"
echo
echo
echo
echo
#:::Similarly, a user can specify a parameter to be stored in a variable:::
#-------------------------------------------------------------------------
echo
echo
echo "enter the parameter you wish to search by:"
read parameter
echo "$parameter was the parameter you typed"
echo
echo
echo
echo
 
#:::And, a user can specify a filename to be stored in a variable:::
#-------------------------------------------------------------------------
echo
echo
echo "Enter file name to be searched"
read filename
if [ -r "$filename" -a -f "$filename" ]
then
clear
 
#:::How can the data stored in that variable be used to search a file?:::
#------------------------------------------------------------------------
#By calling the function "grep function"
 
grepfunction
else
echo "Could not search!"
fi
echo
echo
echo "The entries above match your search"
echo
echo
echo "It is as easy as:-"
echo "1. (Type tool) grep"
echo "2. (Type parameter) a name"
echo "3. (Type the name of the file) Myfile"
echo
echo "All you have to do is type the command at the $ prompt!"


Results...

[jpowers@thebeast test]$ ./grepit.sh

:::Retrieval of Information using 'Grep':::
enter the tool you are using here:
grep
grep was the tool you typed

enter the parameter you wish to search by:
jpowers
jpowers was the parameter you typed

Enter file name to be searched
dat.dat
jpowers
jpowers
jpowers

The entries above match your search
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."

Last edited by Infinite Recursion; Apr 6th, 2005 at 9:17 AM.
Infinite Recursion is offline   Reply With Quote