grep commnad

echo "Enter a,: \c"
read answer
echo
case "$answer" in
a|A)
echo "Enter a file :\c"
read $answer
echo " Enter a string to be searched :\c"
read $answer2
if [ ! -s $answer ]
then
echo " file doesn't exist"
else grep $answer2 $answer # is there an alternative way # to declare this ?
fi
;;

I am not much sure with your problem statement. But I assume , you want to search a string within some file.

Alternate way I know is using awk,

awk "/$searchstring/" $file2bSearched

what you've said is what i want to do

but using grep

Sry ! Have n't understood yr question properly.

What i would do passing of file and string from commnad from command line and do grep like this

grep $2 $1

also ...what o/p do u want from grep, in yr question ?

props,
Solution I suggested do not involve grep, its an alternative to grep.

Why the static requirement that this must be solved using grep? One could well assume that this could be some kind of homework question. Maybe you should try reading the manual page for grep.

Also; your Original Post isn't really a question at all. "Is there an alternative way to declare this". Why do you want to declare it differently? What exactly are you trying to do? What is the purpose of your script? Or is this just what the assignment tells you to do?!

Please review the rules . Looking back through your previous posts it seems you consistently post homework questions on this site, and appear to cause arguments when the point is made. Therefore, I am making the decision to lock this thread before such an argument ensues.

Thanks
ZB