LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


All times are GMT -5. The time now is 10:15 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration