Texts between 2 strings


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Texts between 2 strings
# 1  
Old 07-05-2013
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 06:46 AM..
# 2  
Old 07-05-2013
what have you tried?
# 3  
Old 07-05-2013
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
Code:
$ sed -n '/<2013 start/,/end pdu/{H;/end pdu/{g;/dot1q/s/[^\n]*\n//p;};}' file
<2013 start
request pdu
     dot1q
end pdu

This User Gave Thanks to anbu23 For This Post:
# 5  
Old 07-05-2013
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...
# 6  
Old 07-08-2013
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Aligning Texts

is there any way to align my text so every column begins on the same line as the previous line? here's my command: printf "THEN ( ${SEARCHPATTB} = Hour = ${CALTOTB} ) %8s => %8s NOW ( ${SEARCHPATT} = Hour = ${CALTOT} ) %7s => %7s Reduced By: %7s -${RESULT}"\\n output i'm currently getting... (2 Replies)
Discussion started by: SkySmart
2 Replies

2. Post Here to Contact Site Administrators and Moderators

Can there be alt-texts to icons?

Can you add hover texts (alt-texts) to icons? It is not always obvious what each of them mean just by looking at them. Sometimes it is clear from the url it points to, but for accessibility reasons alone it would be good to have alt-texts as a standard. (1 Reply)
Discussion started by: figaro
1 Replies

3. UNIX for Dummies Questions & Answers

Searching for Multiple texts in a file

Hello guys, I hope anyone can help me with this ... I have a file in which i have around 6000 lines of same format text like 1234567 2345678 3456789 .................... Now what I have to do is that there I have to search these numbers in another file which contains hundreds of... (1 Reply)
Discussion started by: m_usmanayub
1 Replies

4. Programming

How to test many texts generated by many commands ?

Hello, I have hundreds of text files to be tested.They are generated by many commands. I should check whether a word in specific position is right, or whether a word in file A is equal to a word in file B. All the file are not the same. I decide to use shell to test every files, so I had to write... (7 Replies)
Discussion started by: 915086731
7 Replies

5. Shell Programming and Scripting

How to concatenate texts in perl only?

Hi, I want to concatenate the texts in the file but there are different scenario's. Ist Scenario. The contents of file has id`language,sequence number,text,language Here id`language is a key pair to identify the correct language. Sequnce number is the order the text being inserted. Text... (3 Replies)
Discussion started by: vanitham
3 Replies

6. Shell Programming and Scripting

extract texts using awk

Hello, I have two files: File1: a b c d File2: b c e I need 'e' as output.... Thanks.. ---------- Post updated at 12:16 PM ---------- Previous update was at 12:15 PM ---------- (1 Reply)
Discussion started by: shekhar2010us
1 Replies

7. Shell Programming and Scripting

copy and merge texts between two pattern

I need 1. to find all the files from a Folder "folder_name" and from its 4 or 5 sub folders which contain a certain pattern "pattern1". 2. from these files copy and merge all the text between "pattern1" and another different pattern "pattern2" to "mergefile". 3. Get rid of every html tag. 4.... (3 Replies)
Discussion started by: mjomba
3 Replies

8. Shell Programming and Scripting

Separate sentences from two texts, combine them

I havet two books, one in Swedish, the other in English. Two text files. I want to combine them into one, with each sentence having it's translation next to it. ------------ Text file one. Example sentence in English. Example 2 sentence 2 in English 2. -------------- Text file two. ... (2 Replies)
Discussion started by: LaraMej
2 Replies
Login or Register to Ask a Question