Computing.Net > Forums > Unix > Parse file and save in etc/hosts

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Parse file and save in etc/hosts

Reply to Message Icon

Name: Yasir
Date: August 21, 2003 at 10:05:32 Pacific
OS: Linux
CPU/Ram: Intel , 512
Comment:

Hello:

I am very new to shell programming and in need of some help. I have a file sc.cfg that contains some ip addresses as ASCIP.

sc.cfg
--------------
ASCIP=3.87.87.3/255.255.252.0
ASCIP=3.87.86.41/255.255.252.0
ASCIP=3.87.87.45/255.255.252.0

--------------

All I need is a shell script that opens this file (sc.cfg) takes out the 3 ip addresses and stores it in etc/hosts...

Please help.

Thank You & Best Regards



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: August 21, 2003 at 10:51:29 Pacific
Reply:

The IP number without the hostname won't do you a lot of good.

#!/bin/sh
cat sc.cfg | while read line ; do
IP=`echo $line | cut -f 2 -d "=" | cut -f 1 -d "/"`
if [ `grep -c $IP /etc/hosts` -eq 0 ] ; then
echo $IP >> /etc/hosts
fi
done


0
Reply to Message Icon

Related Posts

See More


to split a file writing to remote databas...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Parse file and save in etc/hosts

how to replace a file and save it i www.computing.net/answers/unix/how-to-replace-a-file-and-save-it-i/7216.html

Port Numbers In etc/hosts www.computing.net/answers/unix/port-numbers-in-etchosts/2911.html

deleting rows in a file www.computing.net/answers/unix/deleting-rows-in-a-file/3676.html