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


Reply
  Search this Thread
Old 07-02-2008, 10:17 AM   #1
BlueberryPickles
LQ Newbie
 
Registered: Jul 2008
Posts: 4

Rep: Reputation: 0
Finding Paragraphs that Contain a Search String


Hi everyone,

I have a file that contains a list of descriptions. Here are the first four of them as an example:

<Topic r:id="Stuff/EnglishA">
Stuff here A1
Stuff here A2
Stuff here A3
Stuff here A4
Stuff here A5
</Topic>

<Topic r:id="Stuff/Not_English1">
Stuff here Not1_1
Stuff here Not1_2
Stuff here Not1_3
</Topic>

<Topic r:id="Stuff/EnglishB">
Stuff here B1
Stuff here B2
Stuff here B3
Stuff here B4
</Topic>

<Topic r:id="Stuff/Not_English2">
Stuff here Not2_1
Stuff here Not2_2
</Topic>


What I want to do is to create another file that contains only the descriptions that have a particular topic. For example, I want one file that contains only topics where the first line begins with "<Topic r:id="Stuff/English":

<Topic r:id="Stuff/EnglishA">
Stuff here A1
Stuff here A2
Stuff here A3
Stuff here A4
Stuff here A5
</Topic>

<Topic r:id="Stuff/EnglishB">
Stuff here B1
Stuff here B2
Stuff here B3
Stuff here B4
</Topic>


I have strugled with various sed, awk and perl commands but just haven't got it yet.

Could anyone with a big heart save me please?
 
Old 07-02-2008, 10:28 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Welcome to LQ!!

SED will do this. Take a look at this tutorial:
http://www.grymoire.com/Unix/Sed.html

In particular, look at "Ranges by patterns" and "Multi-line ranges"

For example:
sed -n '/start/,/end/p' filename
prints all lines beginning with one containing "start", through one containing "end"

Please post the code that you are using so we can see where you are.
 
Old 07-02-2008, 10:36 AM   #3
BlueberryPickles
LQ Newbie
 
Registered: Jul 2008
Posts: 4

Original Poster
Rep: Reputation: 0
You are a guru! A million 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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can you make search ...search a string in a link....a url...a web address aus9 LQ Suggestions & Feedback 4 04-16-2008 10:37 AM
finding a string jkeertir Linux - Newbie 3 03-28-2008 05:45 PM
C....Search a string for a string Scrag Programming 4 06-14-2004 05:15 PM
search for my string alaios Linux - General 6 05-08-2004 02:32 PM
Search for a string TheOriginalH Linux - General 5 09-24-2003 11:48 AM


All times are GMT -5. The time now is 01:21 AM.

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