Computing.Net > Forums > Programming > Pulling just IP Addresses from a Text File

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Pulling just IP Addresses from a Text File

Reply to Message Icon

Name: chadfletch17
Date: September 30, 2009 at 11:39:56 Pacific
OS: Ubuntu
Subcategory: Batch
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: September 30, 2009 at 13:23:10 Pacific
Reply:

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



0
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Pulling just IP Addresses from a Text File

Ping list of computers from a txt file www.computing.net/answers/programming/ping-list-of-computers-from-a-txt-file/19843.html

Delete blank lines from a text file www.computing.net/answers/programming/delete-blank-lines-from-a-text-file/14525.html

Extracting Text from a text file www.computing.net/answers/programming/extracting-text-from-a-text-file/18097.html