Texts between 2 strings | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Texts between 2 strings

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-05-2013
giri_luck giri_luck is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 23 July 2013, 3:08 AM EDT
Posts: 51
Thanks: 5
Thanked 0 Times in 0 Posts
Texts between 2 strings

Hi,

I have a file with texts shown below,

Code:
<2013 abc
<2013 start
request pdu
     dot1q
end pdu
response pdu
     dot1q
end pdu

am searching for the text "dot1q" , when it matches in the file , i need the contents between "<2013 start" and "end pdu". Can some one help on this ?

So after the search string is been found [ here it is "dot1q" ] i need the texts between "<2013 start" and the second occurance of "end pdu"

Last edited by giri_luck; 07-05-2013 at 05:46 AM..
Sponsored Links
    #2  
Old 07-05-2013
anbu23's Avatar
anbu23 anbu23 is offline Forum Advisor  
Advisor
 
Join Date: Mar 2006
Last Activity: 31 July 2014, 8:46 AM EDT
Location: Bangalore,India
Posts: 2,089
Thanks: 12
Thanked 131 Times in 126 Posts
what have you tried?
Sponsored Links
    #3  
Old 07-05-2013
giri_luck giri_luck is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 23 July 2013, 3:08 AM EDT
Posts: 51
Thanks: 5
Thanked 0 Times in 0 Posts
Hi,

I was trying with

Code:
sed -n '/<2013 start/,/^<pdu.$/p'

but i do not know how to get the texts matching a word in between.
    #4  
Old 07-05-2013
anbu23's Avatar
anbu23 anbu23 is offline Forum Advisor  
Advisor
 
Join Date: Mar 2006
Last Activity: 31 July 2014, 8:46 AM EDT
Location: Bangalore,India
Posts: 2,089
Thanks: 12
Thanked 131 Times in 126 Posts

Code:
$ sed -n '/<2013 start/,/end pdu/{H;/end pdu/{g;/dot1q/s/[^\n]*\n//p;};}' file
<2013 start
request pdu
     dot1q
end pdu

The Following User Says Thank You to anbu23 For This Useful Post:
RavinderSingh13 (07-05-2013)
Sponsored Links
    #5  
Old 07-05-2013
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 2 September 2014, 1:19 PM EDT
Location: Switzerland - GE
Posts: 5,651
Thanks: 152
Thanked 391 Times in 370 Posts
Quote:
but i do not know how to get the texts matching a word in between.
In other terms your sed is suitable at condition it contains the word you are looking for?
So that is just a test using grep to validate your extraction...
Sponsored Links
    #6  
Old 07-08-2013
Don Cragun's Avatar
Don Cragun Don Cragun is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 2 September 2014, 11:40 PM EDT
Location: San Jose, CA, USA
Posts: 4,506
Thanks: 177
Thanked 1,512 Times in 1,284 Posts
Ravinder Singh sent me private mail saying that this thread had not provided a suitable solution to the satisfaction of the submitter and Ravinder. When I look at this thread, I see a very vague statement of the desired output and a sample script that doesn't work.

I note that vbe has already asked for a clarification of the requirements and no response has been provided. Without a clear statement of what output is desired (and sample output corresponding to the sample input [in CODE tags]), I don't see how anyone can provide any help.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Searching for Multiple texts in a file m_usmanayub UNIX for Dummies Questions & Answers 1 12-31-2011 03:11 PM
How to test many texts generated by many commands ? 915086731 Programming 7 10-24-2011 11:22 AM
How to concatenate texts in perl only? vanitham Shell Programming and Scripting 3 09-21-2011 04:08 AM
extract texts using awk shekhar2010us Shell Programming and Scripting 1 07-22-2011 12:25 PM



All times are GMT -4. The time now is 12:36 AM.