I have the following command that correctly creates the /etc/hosts file that I want to build. However, I cannot write it per the 2nd form due to permissions, of course. So I tried variations of the 3rd form, but it still errors on permissions. Can someone give me a suggestion to try?
cat hosts.tmp ; echo -n "myremotehost " ; cat ip.txt
cat hosts.tmp ; echo -n "myremotehost " ; cat ip.txt > /etc/hosts
cat hosts.tmp ; echo -n "myremotehost " ; echo mypassword | sudo -S cat ip.txt > /etc/hosts