LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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