Simple awk search problem

Hello;

we have :

awk '/reg_exp/,0/

prints every line after the first occurrence of "reg_exp"

But if I want to print rest of the lines AFTER the last occurrence of "reg_exp",
how would I do it ??

Tried :

awk ' ! (/reg_exp/,0)' 

But it errored...

Thank you for any suggestions..

Well this

awk '/reg_exp/,0

has some syntax errors and wouldn't run.

How about a naive approach:

 awk '/regex/{flag=1;next}flag' input

EDIT: oops, I misread the part "after the last occurrence". Sorry

To find out that the occurrence is the last, awk has to search through the whole file. So you either need to scan through file twice (once in the BEGIN block, to find which is the last), or save the lines in an array, which may overflow your memory, if the file is really large. So I would make use of 'tac' which will print the lines in reverse order:

 tac lines | sed -n '/six/{q};p' | tac

Try...

awk '/reg_exp/{x=NR}x{y[NR]=$0}END{if(x)for(z=x;z<=NR;z++)print y[z]}' file1
awk '/reg_exp/{x=NR}x{y[NR]=$0}END{if(x)for(z=x;z<=NR;z++)print y[z]}' file1

Thank you very much for this solution ..

Not sure if I understand the logic in this code..

When you have a chance, may I get you to explain it ??

Thnx again

Thank you, Ygor ..

Trying to understand more complex awk syntax ..