Parsing a text file for ip adresses

John Nielsen knoglen at
Thu Jan 16 08:53:51 PST 2003

On Wednesday 15 January 2003 01:38 pm, you wrote:
> Dan Osterrath wrote:
> >>When i write 'ping [hostname]', it reads the /etc/hosts file, finds the
> >> ip adress for my hostname and pings that. This works beautifully when i
> >> use a static ip adress ( i made a script that automatically updates
> >> /etc/hosts at boot ). However when i use dhclient, i dont know which ip
> >> adress i got assigned. For that i need to parse a really parse
> >> unfriendly file (/var/state/dhcp/dhclient.leases) to figure out what to
> >> put in my /etc/hosts file and quite frankely i have no idea how to do
> >> that.
> >
> >You could parse the output from `ifconfig` instead.
> has a two
> liner for obtainng the IP address from ifconfig's output.

Thanx for the quick reply. Im sorry i was unabel to reply sooner. I am now 
parsing the output of 'ifconfig' instead and that works beautifully. 

And for the archives, here are the exact command i ended up using to get the 
ip adress:

 IP=`ifconfig eth0 | grep "inet addr" | cut -f 2 -d ":" | cut -f 1 -d " "`

John Nielsen
Envie de discuter en "live" avec vos amis ? Télécharger MSN Messenger la 1ère messagerie instantanée de France

Unsubscribe: send email to listar at
and put 'unsubscribe blfs-support' in the subject header of the message

More information about the blfs-support mailing list