0

Suppose I have the next log file:

2023-09-17 00:59:00.245 Start ... here many lines of text#1 (about 1000 lines of text) 2024-02-23 18:48:06.692 INFO [MyClass:myExecutor-3] Some process - enter to step 3 ... here many lines of text#2 (about 6000 lines of text) 2024-02-23 19:38:49.056 INFO [MyClass:myExecutor-4] Some process - complete the process ... here many lines of text#3 (about 3000 lines of text) 

I need to to show lines of logs only between this 2 lines:

2024-02-23 18:48:06.692 INFO [MyClass:myExecutor-3] Some process - enter to step 3 2024-02-23 19:38:49.056 INFO [MyClass:myExecutor-4] Some process - complete the process 

As result must show only this:

... here many lines of text#2 (about 6000 lines of text) 

Is it possible?

1 Answer 1

3

Sure, use the function narrow-to-region. First select everything starting at the beginning of the line after the first match and ending at the end of the line before the second match, then type C-x n n. When a buffer is narrowed, it only displays a selected portion of the text in the buffer. Use widen (C-x n w) to go back to seeing the entire buffer contents.

Edit:

Your comment “How I can select everthing starting at the beginning of the line after the first match and ending at the end of the line before second match? It's about 6000 lines!” makes me think that you don’t know how to select text properly. Sure, if you try to click and drag the mouse over this much text, you’ll never get it right. But Emacs doesn’t make you do that. Just search for the first match, drop the mark with C-space, and then search for the second match. The “region” that commands such as narrow-to-region operate on is always between the location of the point and the most recent mark. By dropping the mark and then moving the point you have selected exactly what you wanted to select.

3
  • How I can select everthing starting at the beginning of the line after the first match and ending at the end of the line before second match? It's about 6000 lines! Commented Mar 11, 2024 at 9:54
  • 1
    Find the first match using C-s, press C-space, find the second match, press C-x n w. Commented Mar 11, 2024 at 9:58
  • @choroba: typo - should be C-x n n as in the answer. Commented Mar 13, 2024 at 2:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.