-2

I need to extract/print lines until a stop pattern. This needs to happen after every 3rd occurrence of start pattern, i.e ERROR_FILE_NOT_FOUND and continue until the end of the file. Below is an example of the log file.

ERROR_FILE_NOT_FOUND
some text
ERROR_FILE_NOT_FOUND
some text
ERROR_FILE_NOT_FOUND
Extract line 1
Extract line 2
Extract line 3
Stop_pattern
some text
ERROR_FILE_NOT_FOUND
some text
ERROR_FILE_NOT_FOUND
some text
ERROR_FILE_NOT_FOUND
Extract line 5
Extract line 6
Extract line 7
Stop_pattern
some text
ERROR_FILE_NOT_FOUND
some text
ERROR_FILE_NOT_FOUND
some text
ERROR_FILE_NOT_FOUND
Extract line 9
Extract line 10
Extract line 11
Stop_pattern

Desired output:

Extract line 1
Extract line 2
Extract line 3
//separate if possible
Extract line 5
Extract line 6
Extract line 7
//separate if possible
Extract line 9
Extract line 10
Extract line 11
//separate if possible
  • 4
    Question exists with answers at stackoverflow.com/q/26144033/7552 – glenn jackman Oct 1 '14 at 15:46
  • that print particular number of line. this quetion is having stop_pattern – user4099249 Oct 1 '14 at 15:53
  • Could you show us your desired output? Do you want everything from the 3rd ERROR_FILE_NOT_FOUND to the end? – terdon Oct 1 '14 at 16:14
0

In awk:

$ awk '/Stop_pattern/{c=0; print ""}; c>=3;/ERROR_FILE_NOT_FOUND/{c++} ' file 
Extract line 1
Extract line 2
Extract line 3

Extract line 5
Extract line 6
Extract line 7

Extract line 9
Extract line 10
Extract line 11
  • not everything from third occurrence, there's stop pattern where it should stop printing and start looking for 3rd occurrence from then on till it finds next stop pattern, – user4099249 Oct 1 '14 at 19:13
  • @user4099249 OK, that's why I asked you to show your desired output. Please edit your question and add it (don't post it in a comment). Anyway, I updated my answer, it should do what you want now. – terdon Oct 1 '14 at 19:20
  • Sorry I'm new forum so did not not there's way to edit question.I see two answer of yours which one I should try, I need start patter and stop patter to be printed as well. – user4099249 Oct 1 '14 at 19:28
  • @user4099249 could you please, please hit the edit link under your question ( or this one: edit) and show us your desired output? You keep adding these details. The new version prints both start and end patterns. Now, please edit your question and add your desired output. – terdon Oct 1 '14 at 19:32
  • is it readable? – user4099249 Oct 1 '14 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.