as a start, you can have sed replace a string with the contents of a variable, e.g.
tail some.file | sed "s/astring/$AVARIABLE/g"
the contents of the variable will be replace by the shell and then interpreted by sed. as a result, if the file contains anything that might be a control character (including other scripting commands) then it will choke. spaces are okay