get last occuerrence of a line with 2 specific words in linux

bash, linux

Solution

Your wording was a bit ambiguous, did you want a line with both alpha AND beta or alpha OR beta. If the first:

grep -EA15 'alpha.*beta|beta.*alpha' | tail -16

if the second:

grep -wA15 'alpha|beta' | tail -16

Problem

I have a text file ( basically a log file) in linux and i have 2 words (alpha, beta). Now i trying to to search these two words in one line and then print that line and next 15 lines in a temp file. there would be many lines with alpha and beta But I need only last occurrence with "alpha" and "beta" and next 15 lines. I'll be thankful if you also tell me command in case number of words increase, like 3 or 4 word to search on same line, alpha, beta, gamma

Original source