LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-13-2010, 11:22 AM   #1
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Rep: Reputation: 16
Thumbs down OutPut IP into aFile - Part II


to cover all the different scenarios i need to take my origional post( http://www.linuxquestions.org/questi...a-file-806382/ ) a level higher. using the ip address of 4th line in FileA with the CIDR using the following code: ( thanks to grail)

Quote:
ipbits=$(ifconfig eth0 | awk -F: 'NR==2{print | "whatmask "$NF}' | awk -F"[ ]*:[ ]*" '/CIDR/{print $2}')
FileA contains:
Quote:
#this a comment
#this a comment
#this a comment
hostname 10.176.20.254
hostname 10.18.13.253
hostname 10.18.16.253
hostname 177.23.56.58
#this a comment
I need to use whatmask program with ip address of the 4th line (ex: 10.176.20.254) with CIDR get the Network Address & direct only ip address to a file. here is an example:

Quote:
$ whatmask 10.176.20.254/20

------------------------------------------------
TCP/IP NETWORK INFORMATION
------------------------------------------------
IP Entered = ..................: c
CIDR = ........................: /20
Netmask = .....................: 255.255.240.0
Wildcard Bits = ...............: 0.0.15.255
------------------------------------------------
Network Address = .............: 10.176.16.0
Broadcast Address = ...........: 10.176.31.255
Usable IP Addresses = .........: 4094
First Usable IP Address = .....: 10.176.16.1
Last Usable IP Address = ......: 10.176.31.254
so i need only below line diected to a file. (from Network Address)
10.176.16.0

thanks for your help.
 
Old 05-13-2010, 12:04 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
Use grep or awk?
 
Old 05-13-2010, 01:39 PM   #3
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Original Poster
Rep: Reputation: 16
i managed to do it. thanks to grail for previous help.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
may server hosting different part of web site must appear as part of a domain amolgupta Linux - Software 6 07-13-2009 01:52 PM
why does it says "afile:cannot execute binary file" littletransformer Programming 7 12-01-2007 10:28 PM
LXer: New Linux Foundation Must Be Part Lawyer, Part Peacemaker LXer Syndicated Linux News 0 01-27-2007 03:33 PM
LXer: Wells Grants in Part IBM's Motion to Limit SCO's Claims! In *Large* Part. LXer Syndicated Linux News 0 06-28-2006 09:33 PM
unzip afile Haroon Linux - General 2 09-04-2004 09:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration