Getting the lines between last occurrence of two patterns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting the lines between last occurrence of two patterns
# 8  
Old 02-14-2008
Quote:
Originally Posted by rvz
How do i use this script, where to put my logfile name Smilie
man sed

either this way: "sed -n '<program>' <filename>"

or that way: "cat <filename> | sed -n '<program>'"

bakunin
# 9  
Old 08-08-2008
how to get the first ocurrence of Started and Finished

sed -n '/^Finished/ {
H
}
$ {
x
p
}
/^Started/,/^Finished/ {
/^Started/ {
h
}
/^Started/ !{
H
}
}' file

can you please tell in detail how is this working, i know there is only some minore changes in the above code to get the first occurrence of Started and Finished. But didn't understand the above code properly
Please help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to print lines from a files with specific start and end patterns and pick only the last lines?

Hi, I need to print lines which are matching with start pattern "SELECT" and END PATTERN ";" and only select the last "select" statement including the ";" . I have attached sample input file and the desired input should be as: INPUT FORMAT: SELECT ABCD, DEFGH, DFGHJ, JKLMN, AXCVB,... (5 Replies)
Discussion started by: nani2019
5 Replies

2. UNIX for Beginners Questions & Answers

Delete multiple lines between blank lines containing two patterns

Hi all, I'm looking for a way (sed or awk) to delete multiple lines between blank lines containing two patterns ex: user: alpha parameter_1 = 15 parameter_2 = 1 parameter_3 = 0 user: alpha parameter_1 = 15 parameter_2 = 1 parameter_3 = 0 user: alpha parameter_1 = 16... (3 Replies)
Discussion started by: ce9888
3 Replies

3. Shell Programming and Scripting

UNIX help to print 50 lines after every 3rd occurrence pattern till end of file

I need help with extract/print lines till stop pattern. This needs to happen after every 3rd occurrence of start pattern and continue till end of file. Consider below is an example of the log file. my start pattern will be every 3rd occurrence of ERROR_FILE_NOT_FOUND and stop pattern will be... (5 Replies)
Discussion started by: NSS
5 Replies

4. Shell Programming and Scripting

How to output all lines following Nth occurrence of string

Greetings experts. Searched the forums (perhaps not hard enough?) - Am searching for a method to capture all output from a log file following the nth occurrence of a known string. Background: Using bash, I want to monitor my Oracle DB alert log file. The script will count the total # of... (2 Replies)
Discussion started by: cjtravis
2 Replies

5. Shell Programming and Scripting

[Solved] Sed/awk print between patterns the first occurrence

Guys, I am trying the following: i have a log file of a webbap which logs in the following pattern: 2011-08-14 21:10:04,535 blablabla ERROR blablabla bla bla bla bla 2011-08-14 21:10:04,535 blablabla ERROR blablabla bla bla bla ... (6 Replies)
Discussion started by: ppolianidis
6 Replies

6. Shell Programming and Scripting

Sed/awk print between different patterns the first occurrence

Thanks for the help yesterday. I have a little modification today, I am trying the following: i have a log file of a webbap which logs in the following pattern: 2011-08-14 21:10:04,535 blablabla ERROR Exception1 blablabla bla bla bla bla 2011-08-14... (2 Replies)
Discussion started by: ppolianidis
2 Replies

7. Shell Programming and Scripting

Extracting text between two patterns 1 and 2 and pattern2 should be second occurrence of the file

Hi All, I have a small query. I have a file containing the following lines File 1: 29-Jul-2011 GMT Static data requires update <Extraction should start here> ----------- ----------- -------------------- ----------------------- ----------- <should stop here> Pattern1 will be time... (2 Replies)
Discussion started by: gangii87
2 Replies

8. Shell Programming and Scripting

How can I get the lines between two patterns?

hi, I have the following file hello world this is to say bye to everyone so bye I want to get the lines from hello to the first bye inclusive into another file? how can I do this (11 Replies)
Discussion started by: JamesByars
11 Replies

9. Shell Programming and Scripting

Searching patterns in 1 file and deleting all lines with those patterns in 2nd file

Hi Gurus, I have a file say for ex. file1 which has 3500 lines in it which are different account numbers and another file (file2) which has 230000 lines in it. I want to read all the lines in file1 and delete all those lines from file2 which has that same pattern as in file1. I am not quite... (4 Replies)
Discussion started by: toms
4 Replies

10. Shell Programming and Scripting

How to get lines in between Patterns?

Hi, I need to create a script that does the following: 1. Read the file for the occurrences of "EXECUTE" and "END" strings. There will be several occurrences of EXECUTE and END strings on the file. 2. The resulting lines in #1, needs to be searched for the word... (11 Replies)
Discussion started by: racbern
11 Replies
Login or Register to Ask a Question