Develop a command line with 10 lines before and after the grep keyword, similar to the linux grep -C command and the less command

Hello, please ask 2 questions.
I want to develop a command line tool based on loki’s http api and logql, and want to achieve the following functions:

  1. Search for the error keyword and its context, similar to the linux command ‘grep -C 10 error a.log’ . I know that logql has log line filter and http range query, but I don’t know how to find the 10 lines before and after it.
  2. Search for the error keyword and support jump search. For example, after searching for the first error keyword, press the n key to jump to the next matching error keyword, and search for the 10 lines before and after the next error.like linux less command.
    Thank you for your guidance
1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.