There is always the awk option. Replace string variable with your contents. This is not an in-place change though. Personally, I tend to not make in-place changes. This is definitely a personal preference. Two things, -v signifies a variable in awk and variable n is used here to match a line number, effectively NR == 1. You could use this in any number of ways just by changing the value of n and s.
string="My New first line"; awk -v n=1 -v s="$string" 'NR == n {print s} {print}' file.source > file.target
Example:
% cat file.source
First Line
Second Line
Third Line
% string="Updated First Line"; awk -v n=1 -v s="$string" 'NR == n {print s} {print}' file.source > file.target; cat ./file.target !698
Updated First Line
First Line
Second Line
Third Line
echo "deb http://extras.ubuntu.com/ubuntu precise main" | sudo tee -a /etc/apt/sources.list-- you also need sudo before tee to get admin privileges. But why on earth would you want to add something on the very top of sources.list? – medigeek Jun 16 '12 at 11:30