Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 10-11-2009, 01:46 PM   #1
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
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910

welcome to LQ ...

Something like this *should work* (untested).
sed -n '/<body>/,/<\/body>/p' file | grep "search string"
Old 10-11-2009, 02:23 PM   #3
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
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
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,362

Rep: Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377
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;


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 Member Intro 2 06-29-2009 07:17 AM
Hello every body, yothkajorn Member Intro 2 05-11-2009 11:31 PM
Hello, every body. gordonyui 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 09:07 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration