May 11, 2005 #1 stu78 Programmer Joined May 29, 2002 Messages 121 Location GB Hi, I need to comment the following line in /etc/hosts using sed, 12.9.9.0 host.internal.com host How is this possible? For me, I cannot do a replace of 12.9.9.0 as this is not unique within hosts. Any Ideas?
Hi, I need to comment the following line in /etc/hosts using sed, 12.9.9.0 host.internal.com host How is this possible? For me, I cannot do a replace of 12.9.9.0 as this is not unique within hosts. Any Ideas?
May 11, 2005 1 #2 PHV MIS Joined Nov 8, 2002 Messages 53,708 Location FR as this is not unique within hosts You have some criteria to distinguish the occurrences ? Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886 Upvote 0 Downvote
as this is not unique within hosts You have some criteria to distinguish the occurrences ? Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
May 11, 2005 Thread starter #3 stu78 Programmer Joined May 29, 2002 Messages 121 Location GB I have thought of using a sed address, however, this seems a bit of overkill? Can I just not find & replace an entire line using SED? Upvote 0 Downvote
I have thought of using a sed address, however, this seems a bit of overkill? Can I just not find & replace an entire line using SED?
May 11, 2005 Thread starter #4 stu78 Programmer Joined May 29, 2002 Messages 121 Location GB Or, If I can just replace 12.9.9.0 host. with #12.9.9.0 host. This would also work, I have tried; sed -e s/12.9.9.0 host./#12.9.9.0 host./g magnus.conf > hosts > tmp && mv tmp hosts But this does not seem to work. Upvote 0 Downvote
Or, If I can just replace 12.9.9.0 host. with #12.9.9.0 host. This would also work, I have tried; sed -e s/12.9.9.0 host./#12.9.9.0 host./g magnus.conf > hosts > tmp && mv tmp hosts But this does not seem to work.
May 11, 2005 #5 PHV MIS Joined Nov 8, 2002 Messages 53,708 Location FR Have you tried something like this ? t=`echo "\t\c"` sed '/^12\.9\.9\.0'"[ $t]*host.internal.com[ $t]*host/s!^!#!" /etc/hosts > output The awk way: awk '$1=="12.9.9.0" && $2=="host.internal.com" && $3=="host"{print "#"$0;next}{print}' /etc/hosts > output Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886 Upvote 0 Downvote
Have you tried something like this ? t=`echo "\t\c"` sed '/^12\.9\.9\.0'"[ $t]*host.internal.com[ $t]*host/s!^!#!" /etc/hosts > output The awk way: awk '$1=="12.9.9.0" && $2=="host.internal.com" && $3=="host"{print "#"$0;next}{print}' /etc/hosts > output Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
May 18, 2005 Thread starter #6 stu78 Programmer Joined May 29, 2002 Messages 121 Location GB Hi, Good idea with the awk - I modified it slightly to be; awk '/12.9.9.0/ && /host.internal.com/ {print "#"$0;next}{print}' hosts > output && mv output hosts and this works good. Thanks PHV. Upvote 0 Downvote
Hi, Good idea with the awk - I modified it slightly to be; awk '/12.9.9.0/ && /host.internal.com/ {print "#"$0;next}{print}' hosts > output && mv output hosts and this works good. Thanks PHV.