I have a text file, modifyhostslist.txt, which contains entries that correspond to entries found in my hosts file. Not every entry in my hosts file needs to be modified, only entries also found in modifyhostslist.txt.The entries found in modifyhostslist.txt are to be commented out in the hosts file.Sample line (entry) found in modifyhostslist.txt: 127.0.0.1 www.domain.comThe following serves as the comment out sequence: #%%#I've attempted to use sed to complete the task, but so far I've been unsuccessful. Here's my most recent stab at it: while read line; do    sed -i 's/'$line'/#%%#'$line'/' /system/etc/hosts;done < modifyhostslist.txtIn addition, the #%%# comments will be removed at specific intervals thereby returning the hosts file to its original condition. I suspect simply rearranging the command which is used to insert the comments can also be used to remove the comments in the hosts file?It seems the awk command might work, but I'm unsure of how to use it as well.
Sed to Modfiy Hosts File
sed;awk;hosts
You used the command: while read line; do    sed -i 's/'$line'/#%%#'$line'/' /system/etc/hosts;done < modifyhostslist.txtAs long as the lines in modifyhostslist.txt match the lines in /system/etc/hosts, that command really should work.If the lines look identical to the eye but the command still does not work, the cause might be a mismatch between the (invisible) line-endings.  DOS/Windows files have two-character line-endings while Unix and Mac use one-character line-endings.  If this is the problem, the solution is to remove the offending characters.  Since hosts is a Unix system file, I expect that it has the correct line-endings and we thus need to remove the surplus \r characters from the modifyhostslist.txt  file.  This can be done as follows:while read line; do    sed -i 's/'$(echo $line | tr -d '\r')'/#%%#'$line'/' /system/etc/hosts;done < modifyhostslist.txt