How can I view log files in Linux and apply custom filters while viewing?

前端 未结 5 1009
慢半拍i
慢半拍i 2021-01-30 12:45

I need to read through some gigantic log files on a Linux system. There\'s a lot of clutter in the logs. At the moment I\'m doing something like this:

cat logf         


        
5条回答
  •  北恋
    北恋 (楼主)
    2021-01-30 13:29

    Use &pattern command within less.

    From the man page for less

    &pattern

              Display  only  lines which match the pattern; lines which do not
              match the pattern are not displayed.  If pattern  is  empty  (if
              you  type  &  immediately  followed  by ENTER), any filtering is
              turned off, and all lines are displayed.  While filtering is  in
              effect,  an  ampersand  is  displayed  at  the  beginning of the
              prompt, as a reminder that some lines in the file may be hidden.
    
              Certain characters are special as in the / command:
    
              ^N or !
                     Display only lines which do NOT match the pattern.
    
              ^R     Don't interpret regular expression  metacharacters;  that
                     is, do a simple textual comparison.
    

提交回复
热议问题