LinuxQuestions.org
Visit the LQ Articles and Editorials section
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

Reply
 
Search this Thread
Old 10-11-2009, 01:46 PM   #1
tpubcom
LQ Newbie
 
Registered: Oct 2009
Posts: 1

Rep: Reputation: 0
Grep data inside <body>*</body> only


Is there a way to use grep or any other command to only search for text inside the body tags of an html file? I don't want the data inside the title or any of the header tags to show up.

Thanks in advance.
 
Old 10-11-2009, 01:54 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,986
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Hi,

welcome to LQ ...

Something like this *should work* (untested).
Code:
sed -n '/<body>/,/<\/body>/p' file | grep "search string"
 
Old 10-11-2009, 02:23 PM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,551
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
But a similar question was asked recently (sorry -- can't find it to give a link) and we came up with a few ingenious ways of doing it and then somebody sanely pointed out that HTML allows a lot of variation in formatting (for example, line ends are only token separators) and that automated editing was very much better done with specialist tools that are written to work with HTML syntax. Made a lot of sense.

Quick netsearch got this page. Might be some use.
 
Old 10-11-2009, 06:19 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,289

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
As catkin said, a proper tool is recommended.
If you know Perl or don't mind learning it, this module may be the one you want;http://search.cpan.org/~gaas/HTML-Parser-3.62/Parser.pm
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hello every body, i'm using redhat linux I don't know about samba server any body seenas Linux - Newbie 2 07-04-2009 03:47 AM
Hi every body ^^ thanhdat LinuxQuestions.org Member Intro 2 06-29-2009 07:17 AM
Hello every body, yothkajorn LinuxQuestions.org Member Intro 2 05-11-2009 11:31 PM
Hello, every body. gordonyui LinuxQuestions.org Member Intro 1 10-01-2008 05:06 AM
Any Body Now? Bilal84 Linux - Networking 2 05-14-2005 02:08 PM


All times are GMT -5. The time now is 03:09 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