Pulling just IP Addresses from a Text File

September 30, 2009 at 11:39:56
Specs: Ubuntu
i have a text document that I need to pull just the IP addresses from.
I need to know what king of script or command i should use to do this.

See More: Pulling just IP Addresses from a Text File

Report •


#1
September 30, 2009 at 13:23:10
Your requirements are very thin. But since you are using Linux, if you have a file myhosts.txt that looks like this:

10.9.6.91 fred fred.com
10.9.6.92 nails nails.com
10.9.6.43 jim jim.com
10.9.6.81 lester lester.com

The IP address is the first field. You can write a small bash script that grabs the field and prints it:

#!/bin/bash

while read ipadd f2 f3
do
   echo $ipadd
done < myhosts.txt



Report •
Related Solutions


Ask Question