Writing Code

  1. The problem statement, all variables and given/known data:
    Write a script that will perform the grep command on a user defined file and a user defined pattern

  2. Relevant commands, code, scripts, algorithms:
    must use grep command (that is the only piece of information that was given)

  3. The attempts at a solution (include all code and scripts):

clear
loop=y
while [ "$loop" = y ]
do
 tput cup 2 23; echo " ~*~*~*~*~*~*~*~*~*~*~*~ "
 tput cup 3 23; echo " * Search for a Pattern * "
 tput cup 4 23; echo " ~*~*~*~*~*~*~*~*~*~*~*~ "
 tput cup 6 5; echo "Type in the pattern and path to the file you want to search for below," 
 tput cup 7 5; echo "or type Q to return to previous screen."
 tput cup 9 10; echo "Ex. : help /home/james/project/help"
 tput cup 11 5; 
read choice || continue
  case $choice in
    [Q,q]) clear; exit ;;
    *) grep * ;; esac
done

I understand that the grep * is telling it to look for a wildcard, however, I am not sure what it is that I need to write on that line.

4) Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Fort Valley State University, Fort Valley Ga, Dr. Wang, CSCI 3331

In a spot audit of homework questions, I did find where Dr. Wang at FVSU teaches CSCI 3331:

http://wanghaixin.com/

Thanks!

https://fvsu.gabest.usg.edu/pls/B330/bwckschd.p\_disp\_listcrse?term\_in=200908&subj\_in=CSCI&crse\_in=3331&crn_in=24418

---------- Post updated at 06:47 PM ---------- Previous update was at 04:19 PM ----------

I have determined that I need to use

echo "$choice"

but the only problem is I dont know how to make grep run the echo code

---------- Post updated at 07:18 PM ---------- Previous update was at 06:47 PM ----------

update 2:

I figured out that I can complete this task by using this command:

 grep `echo "$choice"` 

now the only thing I have left is to figure out how to make it scrollable... which I know i need to use

 more 

but not sure exactly how to do that

---------- Post updated at 07:31 PM ---------- Previous update was at 07:18 PM ----------

Final Update:

was able to complete the project, here is my final code

clear
loop=y
while [ "$loop" = y ]
do
 tput cup 2 23; echo " ~*~*~*~*~*~*~*~*~*~*~*~*~ "
 tput cup 3 23; echo " * Search for a Pattern  * "
 tput cup 4 23; echo " ~*~*~*~*~*~*~*~*~*~*~*~*~ "
 tput cup 6 5; echo "Type in the pattern and path to the file you want to search for below," 
 tput cup 7 5; echo "or type Q to return to previous screen."
 tput cup 9 10; echo "Ex. : help /home/james/project/help"
 tput cup 11 5;
read choice || continue
 case $choice in
    [Q,q]) clear; exit ;;
    *) clear; tput cup 13 0; grep `echo "$choice"` | more; clear ;; esac
done