LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Closed Thread
  Search this Thread
Old 12-01-2005, 10:13 PM   #1
binaryechoes
LQ Newbie
 
Registered: Jul 2005
Posts: 3

Rep: Reputation: 0
Parsing out html with egrep


I need to cut a dynamic piece of content/syntax out of an html file on a
regular basis. The following code is an example of what I need to awk|cat
sed|head|cut|egrep out

<h2>Network Sensor XPUs</h2>
<table class="description" width="90%" cellspacing="1" cellpadding="15"
align="center"><TR><TD WIDTH="10%" ALIGN="center"
class="descriptionHeader"><b>XPU Number</b></TD><TD WIDTH="10%"
ALIGN="center" class="descriptionHeader"><b>Date</b></TD><TD ALIGN="center"
class="descriptionHeader"><b>Description</b></TD><TR>
<TD ALIGN=CENTER class="description" ALIGN="center"><A
HREF="ican'tposturls.no.good"><b>NS_24.22</b></A></TD><TD
class="description" ALIGN="center">11-23-2005</TD><TD
class="description">This critical Content Update XPU (X-Press Update),
featuring
Virtual Patch technology, contains 1 new event and provides
protection for an Internet Explorer vulnerability that allows
remote code execution. For more information about this
vulnerability, see the following X-Force Alert:
</TD>
</TR>

I've tried numerous command options/syntax but I'm still unable to achieve
this.

[user@box]# cat html.file | egrep '[<h2>Network Sensor XPUs</h2>.*</TD>]' >
newhtml.file

So...in essence I need everything from "<h2>Network Sensor XPUs</h2>" ->
"</TR>".

Any help???

Thanks!

- J
 
Old 12-01-2005, 11:50 PM   #2
Vgui
Member
 
Registered: Apr 2005
Location: Canada
Distribution: Slackware
Posts: 496

Rep: Reputation: 31
Well, you double posted this, but I'll answer here.
Your simplest bet is to not bother piping anything, just use links (a text based browser, http://artax.karlin.mff.cuni.cz/~mikulas/links/ in case you didn't know). If you run it like so:
Code:
links -dump file.html
This will strip all HTML and print the plain text file to terminal, so you can pipe that out to a file and off you go.
Hope that helps.
 
Old 12-02-2005, 12:31 AM   #3
prabuayyappan
Member
 
Registered: Sep 2005
Location: Coimbatore
Distribution: Prabuayyappan
Posts: 32

Rep: Reputation: 15
Try this
sed -n '/\<h2\>/,/\<tr\>/w newfile' oldfile.html
 
Old 12-02-2005, 12:41 AM   #4
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,612

Rep: Reputation: 68
As noted. I believe the Software forum was the most appropriate forum, so I'll close this thread.
Please post follow ups at:
http://www.linuxquestions.org/questi...hreadid=388489

In the future, please choose the most appropriate forum to place your question in, and place it one time in only that forum.

Thank you!

Closed.
 
  


Closed Thread


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing out html with egrep binaryechoes Linux - Software 2 12-02-2005 11:49 PM
Parsing HTML Source Code Itsu Linux - General 4 10-08-2005 01:44 AM
HTML parsing library nodger Programming 1 09-01-2005 01:42 AM
HTML parsing with HTML::TreeBuilder smaida Programming 0 07-10-2005 09:58 PM
Parsing HTML using Perl smaida Programming 2 05-29-2004 01:20 PM


All times are GMT -5. The time now is 01:26 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration