LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 10-08-2004, 01:59 PM   #1
airman99
LQ Newbie
 
Registered: Aug 2004
Distribution: Gentoo
Posts: 26

Rep: Reputation: 15
need help parsing text file


I'm trying to use BASH to extract an IP address from my router using the web interface of my router. The text from the router's page is as follows:

[snip]
...
PPPoE
[shim.gif] [32]Subnet mask
1.1.1.1
[shim.gif] [33]Wan IP
2.2.2.2
[shim.gif] [34]Default gateway
3.3.3.3
[shim.gif] [35]DNS Address
...
[snip]

I want to extract the IP (2.2.2.2) on the line right under the text "Wan IP". I can get almost there with lynx x.x.x.x -dump | grep "Wan IP", but the IP is on the line after the text...

So how can I parse a text file/output to find all the text AFTER the token "Wan IP[return][space][space][space]" up to but not including the token "[return]"?

I'm sure this isn't a difficult grep/cut/awk problem, but I'm having difficulty getting to my end product here.

Thank in advance for any help that can be provided...
 
Old 10-08-2004, 02:52 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Is this what you need?

$ lynx x.x.x.x -dump | awk 'BEGIN { RS="[" } /Wan IP/ { print $NF }'

When used with the above example output, it will return 2.2.2.2

Hope this helps.
 
Old 10-08-2004, 09:09 PM   #3
airman99
LQ Newbie
 
Registered: Aug 2004
Distribution: Gentoo
Posts: 26

Original Poster
Rep: Reputation: 15
Wow! You're a genius!

(now I have to sit down and figure out what the command actually does)

Thanks!
 
  


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
Need help parsing text file scilec Programming 5 12-02-2004 01:00 PM
Parsing large text file with perl smaida Programming 5 09-13-2004 04:33 AM
Parsing Text from a html file. Rezon Programming 6 10-18-2003 12:09 AM
Parsing a tab delimited text file jajanes Programming 9 08-08-2003 10:34 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 12:33 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