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?

a_subscriber
  • 4,062
  • 1
  • 18
  • 56

1 Answers1

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.

db48x
  • 17,977
  • 1
  • 22
  • 28
  • 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! – a_subscriber Mar 11 '24 at 09:54
  • 1
    Find the first match using C-s, press C-space, find the second match, press C-x n w. – choroba Mar 11 '24 at 09:58
  • @choroba: typo - should be C-x n n as in the answer. – NickD Mar 13 '24 at 02:00