The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 10-16-2008
hcclnoodles hcclnoodles is offline
Registered User
  
 

Join Date: Mar 2002
Posts: 272
delete entry from /etc/hosts file ?

Hi there

I have a requirement where i have to globally remove a hosts file entry from all boxes e.g.


Code:
10.01.10.1           my_server1

normally for 'in-line' editing of files without passing it out to another fle and copying it back etc which is messy, Ive been using the fantastic "perl -pi -e" substitution command. However in this case I want to literally delete the line which im not sure that the perl command can do ?

But ....two things

I want to make sure i delete the line ONLY if both the ip AND the hostname are as defined (so that i know im deleting only this line)

and

the gap between the IP and hostname within the hosts file is variable with any potential number of spaces or tabs in between the two

Does anybody have an idea on how i can achieve this ?

Any help on this would be great