LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-15-2004, 12:09 PM   #1
bruoersolitario
LQ Newbie
 
Registered: Apr 2004
Posts: 3

Rep: Reputation: 0
Text parsing question


hi, I am trying to write a script for my router/firewall that parses from ifconfig output the ip address of a network adapter, merge the resuling IP with another file to generate a variable string and then pass that string to my firewall script. I have successfully extracted the IP address but am unable to get the variable string to generate properly, text is on two separate lines rather than the same line. In addition I have yet to find a way to insert the resulting variable string to the beginning of my firewall script. Any tips/ Suggestions? BTW running RegHat 9

ifconfig ppp0> /etc/ip/ipinfo
grep 'addr' /etc/ip/ipinfo > /etc/ip/ipinfo2
cut --characters=21-35 /etc/ip/ipinfo2 > /etc/ip/ipaddress
echo DSLIP= > /etc/ip/ipvar
cat /etc/ip/ipaddress >> /etc/ip/ipvar

Thanks
Bryan
 
Old 04-15-2004, 01:45 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Try this:
/sbin/ifconfig eth0|grep "inet addr"|awk {'print $2'}|cut -d: -f2

Just change "eth0" to your adapter name.
 
Old 04-15-2004, 01:59 PM   #3
bruoersolitario
LQ Newbie
 
Registered: Apr 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks that worked great, the other solution I came up with involved convoluted sed strings.
 
Old 04-15-2004, 02:07 PM   #4
bruoersolitario
LQ Newbie
 
Registered: Apr 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Any suggestions as to how I can get the resulting IP into a variable in a separate script?
 
Old 04-15-2004, 02:12 PM   #5
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
You can use:
ipaddr=`/sbin/ifconfig eth0|grep "inet addr"|awk {'print $2'}|cut -d: -f2`
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing a text filw which contains flowdiagram saravanan1979 Programming 1 06-29-2005 03:01 PM
Need help parsing text file scilec Programming 5 12-02-2004 01:00 PM
need help parsing text file airman99 Linux - General 2 10-08-2004 09:09 PM
Parsing Text from a html file. Rezon Programming 6 10-18-2003 12:09 AM
Parsing a file for a string of text jamesmwlv Linux - General 2 12-02-2002 07:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:50 AM.

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