sed print matching pattern


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sed print matching pattern
# 1  
Old 02-15-2012
sed print matching pattern

Hi,
i have data file like:
START1
a
b
STOP
c
d
START2
e
STOP
f
START3
g
STOP

When one of the START<count> variable is passed, i should print all lines matching this until the first 'STOP'

for example if 'START2' is provided for match, i should get the result as:
START2
e
STOP

How to use sed or another utility to achieve this?

I tried the following and it didn't work:
Code:
sed '/START2/,/STOP/'

Thanks,
-srinivas yelamanchili
# 2  
Old 02-15-2012
If you turn off 'printing' by default (-n) and then put a print command after your address pair, it will work as you intended.

Code:
sed -n '/START2/,/STOP/p' input-file

This User Gave Thanks to agama For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Print 2 matching pattern

How to a first 3 lines lines that matches 1st pattern and 1 line that matches 2nd line. Sample.txt Line 1: /*--- ABC_BA_ABCABC -----*/ Line 2: Line 3: insert_job: ABC_BA_ABCABC job_type: BOX Line 4: blah blah Line 5: max_run_alarm: 5 Line 6: blah blah ---- ----- Line 20: /*---... (4 Replies)
Discussion started by: bobbygsk
4 Replies

2. Shell Programming and Scripting

Print lines after matching two pattern

would like to print everything after matching two patterns AAA and BBB. output : CCC ZZZ sample data : AAA BBB CCC ZZZ (4 Replies)
Discussion started by: jhonnyrip
4 Replies

3. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

4. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

5. Shell Programming and Scripting

Want to print out lines with a matching pattern from file

Hi all, I want to search for strings in file1 that can be found in file2 and print out the whole line when matching pattern is found. I have used the below command, but this is not working for me, because it is writing out only the matching patterns from file2, not the whole line. fgrep -o... (2 Replies)
Discussion started by: MonikaB
2 Replies

6. Shell Programming and Scripting

How to print all the lines after pattern matching?

I have a file that contains... Number -------------------- 1 2 3 4 i want to print all the numbers after the hyphen ... (6 Replies)
Discussion started by: ankitknit
6 Replies

7. Shell Programming and Scripting

I want to print next 3 lines after pattern matching.

Dear Experts, I have file called file1 in which i am greping a pattern after that i want to next 3 lines when that pattern is matched. Ex:- file1 USA UK India Africa Hello Asia Europe Australia Hello Peter Robert Jo i want to next 3 lines after matching Hello... (12 Replies)
Discussion started by: naree
12 Replies

8. Shell Programming and Scripting

Print block of lines matching a pattern

Hi :), I am using the script to search "MYPATTERN" in MYFILE and print that block of lines containing the pattern starting with HEADER upto FOOTER. But my problem is that at some occurrence my footer is different e.g. ";". How to modify the script so that MYPATTERN between HEADER and different... (1 Reply)
Discussion started by: vanand420
1 Replies

9. Shell Programming and Scripting

Pattern matching in Duplicated file and print once

Dear Experts, I have many alarms appeared in a file twice, i want to grep them with this info EVTTIME & DOMAIN, and print them in second file with 1 occurance. I have tried uniq -d test.txt > newfile and awk '!arr++' test.txt > newfile both are not working Please help me with this!!! ... (1 Reply)
Discussion started by: Danish Shakil
1 Replies

10. Shell Programming and Scripting

pattern matching and print with sed

Hi It is possible with sed to print a pattern within a line matching regexp? So, the line looks like : 19:00:00 blablablabla jobid 2345 <2> the regexp is "jobid 2345" and the pattern is 56434. That the code for find... (2 Replies)
Discussion started by: nymus7
2 Replies
Login or Register to Ask a Question