I am doing a find and replace with sed, replacing the BASH variable $a (when at the start of a new line) with the BASH variable $b:
$a
$b
This should work:
sed -i "0,/^\$a/s//\$b/" ./file.txt
You can read more about this at http://www.grymoire.com/Unix/Sed.html#toc-uh-29