Search for a pattern in a file and print previous lines from a particular point

Hi,

I am new to ksh scripting and I have a problem.
I have a file in which I have to search for a particular pattern say 'a' then from that line I need to search for another pattern say 'b' in the previous lines and thne print the file from pattern 'b' till the end of file.

For eg:

============
aaaaaaaa
bbbbbbbb
ccccccccc
dddddddddd
eeeeeeeee

Now I need to search for string ccccccc from there I need to search for the first occrance of ===== pattern and from that point I need to print till the end of the file. This is so complicated because the pattern repeats in a similar way in the file.

I know this is very confusing :slight_smile: please let me know if i need to clarify anything thats mentioned above

Something like this??

root@jeepanywhere /usr/src # cat test.log
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
root@jeepanywhere /usr/src # sed -n '/^2/,/^4/{/LABEL$/!p}' test.log
2
3
4
2
3
4
2
3
4

I am not able to understand this command very clearly, but this is wat I want, please tell me if that sed command will give me the below output:

suppose I have a file like the one below:

start of file-----
***********
1
2
3
4
5

***********
6
7
8
9

end of file-----
Now for eg I need to search for 8, then search for the first occurance of the pattern ***** thats jus few lines(no. of lines not fixed) above 8...then from there I need to print till end of file....
so my output needs to be something like this:
***********
6
7
8
9

end of file-----

Thanks in advance...