Deleting the last line with sed

sed -i '$d' ~/hosts
Check:
tail ~/hosts