How to avoid a long line and a large output of grep?

search for a string with grep, and the result is a large piece of output on the screen, which feels endless and is probably a long line. Please look at the picture

when the string you are looking for is in such a long line, how can you avoid this kind of output?

if grep can"t solve it, is there another alternative text search command that can solve it?

Thank you!

Feb.16,2022

you can use the grep option-o, which can be combined with a matching pattern, such as ". {0memt 10} < original pattern >. {0jie 10}" to see some of the contexts around it:

   -o - 
          PATTERN

.. Or-c:

   -c -  count
          ; 
          -v -  inverse-match
                                  

for example:

 grep -oE ".{0,20}mysearchstring.{0,20}" myfile    

man grep is a guide. You can show only the matching part, such as

grep -o keyword file

or count the number of rows that appear

grep -c keyword file
  • Grep cannot Filter persistent log

    I use docker logs-f container_name | grep xxx to have the effect of Filter? Then I tried other continuously increasing log files and found that grep had no effect ....

    Mar.31,2021
  • How to take the result of awk as the pattern parameter of grep?

    for example grep 20180906834424 test.log | awk {print $2} the above code will produce a result. How can I use this result as a parameter of grep to re-search the test.log file? grep 20180906834424 test.log | awk {print $2} | xargs grep PATT...

    May.27,2021
  • Grep in zsh cannot match ^ correctly

    problem description what I may have described is a bit of a problem, maybe it has nothing to do with zsh. The specific problem is: first of all, the content in my file1 is as follows: asdsdf sdfsdbbb abbbb then I run the following command in iterm:...

    Jun.29,2021
  • What does the'~ $'after this bash code grep mean?

    excuse me: what does the ~ $ after this bash code grep mean? grep-z-vE ~ $ Baidu and Google have no results. Who can give me some advice? Thank you very much! ...

    Sep.08,2021
  • Invalid grep

    execute the following command: ps aux | grep-n redis-server | grep-v grep the process information of redis-server can be found normally. (Note: grep-v grep is to exclude the process information of grep itself from the results) but write it as a...

Menu