Script for writing to files with sed

I have a problem with syntax methinks, when it comes to sed.

This is my script for a user to type sed commands:-

yes=y

function writefunction
{
$tool $command $newfilename $filename
}

echo
echo
echo "1. Type the name of the tool you are using i.e sed."
         read tool
echo
echo "2. Type any criteria you are searching for. And remember:-"
echo "   You can do this in conjunction with command options like -n or p to affect the search and view output."
echo "   You can also search characters or whole names by enclosing them in / /, but do not forget to tell the tool what to"
echo "   do with those characters - Use the 'w' write command!"
         read command
echo
echo "3. Type a name for a new file where the output is to be redirected."
         read newfilename
echo
echo "4. Type the name of the original file you searched i.e Myfile"
         read filename
#------------------------------------------------------------------------
#Call the function 'writefunction'
echo
echo "Your results are:-"
echo "--------------------------------------"
             writefunction
echo "--------------------------------------"
echo
echo "Do you want to see the contents of the file you just created?"
echo "Type 'y' for Yes. Press any key for No."
      read answer
    if [ "$answer" = "$yes" ]
     then
      clear
 cat $newfilename
    else
echo "New file $newfilename will not be displayed at this time."
    fi

echo "Where do you want to go?"
echo
echo "------------------"
echo "1. Previous Menu"
echo "2. Main Menu"
echo "3. QUIT"
echo
echo "Please select (1,2 or 3)................."
read menunumber
case $menunumber in
     1)./page2;;
     2)./page1;;
     3)echo "You have Quit the program. To begin again type:- ./page1"
esac
echo
echo

Basically, a user is prompted to type a sed command that will interrogate a file they specify and based on criteria they specify. That information is then written to a new file that they give a name to. All of their responses are stored in variables, that are located in a function to be executed later on in the program.

I think the problem lies in my sed syntax.

To test it I type this in the stages as set out by the program:-

1. sed (the command)
2. /Anderson/w (the criteria)
3. testfile (the file to be written to)
4. filetest(the file to be interrogated)

I have also tried:-

1. '/Anderson/w
2. testfile'  

I get:-

sed: Couldn't open file : No such file or directory

Any syntax ideas?
Or any other advice as to what I am doing wrong?

Cheers,

trufla

One obvious one I picked up on was:

That should be

function writefunction
{
$tool $command $filename > $newfilename 
}

aaah, I hadn't thought of that! Will give it a go!

Cheers!

trufla

That works!

I was getting the user to type '>' so it was stored in the variable.

the script didn't like this at all!

Thanks for that!