1834456 Members
2823 Online
110067 Solutions
New Discussion

Editing the Host file

 
SOLVED
Go to solution
George Abraham_3
Occasional Advisor

Editing the Host file

Hello Admins,

I currently have a file with about 300 lines of the following:



erdpri.salem.gsk.com. 165.156.1.52

erdbck.salem.gsk.com. 165.156.1.53

erdvxt.salem.gsk.com. 165.156.1.54



I need to insert "IN A" (minus the double quotes) in between the

two fields can anyone help me with a script? It needs to look like

this...


erdpri.salem.gsk.com. IN A 165.156.1.52

erdbck.salem.gsk.com. IN A 165.156.1.53

erdvxt.salem.gsk.com. IN A 165.156.1.54


Thanks In advance
George
5 REPLIES 5
Biswajit Tripathy
Honored Contributor
Solution

Re: Editing the Host file

cat /etc/hosts | awk '{printf("%s IN A %s\n",$1,$2)}' > /etc/hosts.NEW

- Biswajit
:-)
Deepak Kulkarni
Regular Advisor

Re: Editing the Host file

Hi George

vi /etc/hosts

:1,$ s/erdbck.salem.gsk.com/erdbck.salem.gsk.com IN A/g


Regards
Deepak
Joseph Loo
Honored Contributor

Re: Editing the Host file

hi,

try this:

# sed 's/salem.gsk.com./salem.gsk.com. IN A/' /etc/hosts > /etc/hosts.replaced

since the domain name, salem.gsk.com is the common variable to replace.

regards.
what you do not see does not mean you should not believe
Nguyen Anh Tien
Honored Contributor

Re: Editing the Host file

I agree with Biswajit Tripathy. But octet1 is same, using vi is possible
#vi /etc/hosts
:1,$s/165/IN A 165
vi will replace for U.
HTH
tienna
HP is simple
George Abraham_3
Occasional Advisor

Re: Editing the Host file

For all you who replied,

Thanks a lot for the wonderful timely support.Thank got the ITRC support..

Cheers
george