grep inside less?Is it possible to save filtered results from lessCommand that highlights regex in text?Get...

Does two puncture wounds mean venomous snake?

Why should public servants be apolitical?

Keeping a Weakness Secret

How can I read one message at a time from /var/mail

What is the best way to cause swarm intelligence to be destroyed?

As a 16 year old, how can I keep my money safe from my mother?

Is multiplication of real numbers uniquely defined as being distributive over addition?

Are there any financial disadvantages to living significantly "below your means"?

Does this Foo machine halt?

In the movie Harry Potter and the Order or the Phoenix, why didn't Mr. Filch succeed to open the Room of Requirement if it's what he needed?

A question about 'reptile and volatiles' to describe creatures

What word can be used to describe a bug in a movie?

Dropdowns & Chevrons for Right to Left languages

Is refreshing multiple times a test case for web applications?

In a topological space if there exists a loop that cannot be contracted to a point does there exist a simple loop that cannot be contracted also?

Why does this Pokémon I just hatched need to be healed?

Infeasibility in mathematical optimization models

Are there any differences in causality between linear and logistic regression?

Double blind peer review when paper cites author's GitHub repo for code

Should I self-publish my novella on Amazon or try my luck getting publishers?

How to identify the wires on the dimmer to convert it to Conventional on/off switch

Acceptable to cut steak before searing?

Can I call myself an assistant professor without a PhD

Shabbat clothing on shabbat chazon



grep inside less?


Is it possible to save filtered results from lessCommand that highlights regex in text?Get 'less' to display filenameless '+>' /path/to/fileLive replacement, while viewing log using LESSHow to export a subset of a 'less' outputWhen to use grep, less, awk, sedDifference between less -r and less -RLess is broken inside GNU ScreenOverride less defaults(Possible) inconsistent behavior of grep and less






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







54















I'm currently sifting through a lot of unfamiliar logs looking for some issues. The first file I look at is Events.log, and I get at least three pages in less which appear to display the same event at different times – an event that appears to be fairly benign.
I would like to filter this event out, and currently I quit less and do something like



grep -v "event text" Events.log | less


This now brings a number of other common, uninteresting events that I would also like to filter out. Is there a way I can grep -v inside of less? Rather than having to do



egrep -v "event text|something else|the other thing|foo|bar" Events.log | less


It strikes me as a useful feature when looking at any kind of log file – and if less isn't the tool, is there another with the qualities I seek? Just a less-style viewer with built in grep.










share|improve this question

































    54















    I'm currently sifting through a lot of unfamiliar logs looking for some issues. The first file I look at is Events.log, and I get at least three pages in less which appear to display the same event at different times – an event that appears to be fairly benign.
    I would like to filter this event out, and currently I quit less and do something like



    grep -v "event text" Events.log | less


    This now brings a number of other common, uninteresting events that I would also like to filter out. Is there a way I can grep -v inside of less? Rather than having to do



    egrep -v "event text|something else|the other thing|foo|bar" Events.log | less


    It strikes me as a useful feature when looking at any kind of log file – and if less isn't the tool, is there another with the qualities I seek? Just a less-style viewer with built in grep.










    share|improve this question





























      54












      54








      54


      18






      I'm currently sifting through a lot of unfamiliar logs looking for some issues. The first file I look at is Events.log, and I get at least three pages in less which appear to display the same event at different times – an event that appears to be fairly benign.
      I would like to filter this event out, and currently I quit less and do something like



      grep -v "event text" Events.log | less


      This now brings a number of other common, uninteresting events that I would also like to filter out. Is there a way I can grep -v inside of less? Rather than having to do



      egrep -v "event text|something else|the other thing|foo|bar" Events.log | less


      It strikes me as a useful feature when looking at any kind of log file – and if less isn't the tool, is there another with the qualities I seek? Just a less-style viewer with built in grep.










      share|improve this question
















      I'm currently sifting through a lot of unfamiliar logs looking for some issues. The first file I look at is Events.log, and I get at least three pages in less which appear to display the same event at different times – an event that appears to be fairly benign.
      I would like to filter this event out, and currently I quit less and do something like



      grep -v "event text" Events.log | less


      This now brings a number of other common, uninteresting events that I would also like to filter out. Is there a way I can grep -v inside of less? Rather than having to do



      egrep -v "event text|something else|the other thing|foo|bar" Events.log | less


      It strikes me as a useful feature when looking at any kind of log file – and if less isn't the tool, is there another with the qualities I seek? Just a less-style viewer with built in grep.







      bash grep logs less






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 2 '15 at 9:45









      G-Man

      15.2k9 gold badges44 silver badges82 bronze badges




      15.2k9 gold badges44 silver badges82 bronze badges










      asked Jan 15 '15 at 11:07









      forquareforquare

      2,3234 gold badges14 silver badges29 bronze badges




      2,3234 gold badges14 silver badges29 bronze badges

























          3 Answers
          3






          active

          oldest

          votes


















          85














          less has very powerful pattern matching.  From the man page:




          &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.



            ____________
            Certain characters are special
            if entered at the beginning of the pattern;
            they modify the type of search
            rather than become part of the pattern.



             (Of course ^N and ^R represent Ctrl+N
          and Ctrl+R, respectively.) 



          So, for example, &dns will display only lines that match the pattern dns,
          and &!dns will filter out (exclude) those lines,
          displaying only lines that don't match the pattern.



          It is noted in the description of the / command that




            The pattern is a regular expression,
            as recognized by the regular expression library supplied by your system.



          So





          • &eth[01]  will display lines containing eth0 or eth1


          • &arp.*eth0 will display lines containing arp followed by eth0


          • &arp|dns  will display lines containing arp or dns


          And the ! can invert any of the above. 
          So the command you would want to use for the example in your question is:



          &!event text|something else|the other thing|foo|bar


          Also use /pattern and ?pattern
          to search (and n/N to go to next/previous).






          share|improve this answer























          • 1





            This is almost there! In less, using '&!<1stpattern>' allows me to 'hide' lines with a pattern on, however it only applies to one pattern at a time, so if I find a second pattern and apply '&!<2ndpattern>', lines that matched the first pattern and were hidden, are now visible. So very close!

            – forquare
            Jan 15 '15 at 11:19











          • @forquare: There's a command history that you can access with the up & down arrows keys. So press &! and then press an arrow key.

            – PM 2Ring
            Jan 15 '15 at 11:34











          • @forquare: And I just discovered that the history is saved, so your old patterns will be available next time you run less; I don't know if it's preserved after rebooting, though.

            – PM 2Ring
            Jan 15 '15 at 11:40






          • 1





            @orion that was the last bit I was missing - how to concatenate patterns together. I though I had tried the pipe symbol before and it failed, but now I try again it works! So: &!<pattern1>|<pattern2>|<pattern3> will remove lines with pattern1 or pattern2 or pattern3

            – forquare
            Jan 15 '15 at 11:47






          • 1





            I figured it out. Homebrew dupes has the latest version. I just had to kick bash because it wasn't grabbing the right file (even though which told me it was grabbing /user/local/bin/less).

            – spinlock
            Mar 31 '15 at 20:17



















          6














          Building on orion's answer, the less(1) man page describes




          /pattern



            Search forward in the file for the N-th line
            containing the pattern. 
            N defaults to 1. 
            The pattern is a regular expression,
            as recognized by the regular expression library supplied by your system. 
            The search starts at the second line displayed
            (but see the -a and -j options, which change this).

            Certain characters are special
            if entered at the beginning of the pattern;
            they modify the type of search
            rather than become part of the pattern:



            ^N or !



              Search for lines which do NOT match the pattern.

            ^E or *
              Search multiple files. 
              That is, if the search reaches the END of the current file
              without finding a match,
              the search continues in the next file in the command line list.

            ^F or @
              Begin the search
              at the first line of the FIRST file in the command line list,
              regardless of what is currently displayed on the screen
              or the settings of the -a or -j options.

            ^K

              Highlight any text
              which matches the pattern on the current screen,
              but don't move to the first match (KEEP current position).

            ^R

              Don't interpret regular expression metacharacters;
              that is, do a simple textual comparison.



            ____________
            Commands may be preceded by a decimal number,
            called N in the descriptions …



             (Of course ^N and ^E, etc., represent
          Ctrl+N and Ctrl+E, etc.) 



          It turns out that &pattern
          and /pattern work well together. 
          For example, the commands





          • &!arp|dnsEnter


          • /Ctrl+Kfail|fatal|fault|sd[a-z][0-9]Enter


          typed in either order, will hide (exclude) all lines
          containing arp or dns (like grep -v), and then, in the remaining lines,
          highlight all occurrences of fail, fatal, fault,
          or anything that looks like the name of a SCSI device (sd[a-z][0-9]). 
          Note that lines that contain arp or dns,
          and also fail or any of the other danger words,
          will not be displayed.






          share|improve this answer



































            0














            Over the last few months, I have become somewhat enamoured of fzf.



            In your case, as long as context is not needed (i.e., the equivalent of grep's -A, -B, or -C is not needed, and by the way, less's & also has the same limitation), then fzf is a very powerful tool.



            Here's a silly example:



            printf "%sn" {aa,bb,cc}{dd,ee,ff}{gg,hh,ii} | fzf


            If you run that, and play with inputs like aa | bb dd | ee !gg !hh and so on, you will quickly see what is happening.



            Fzf's documentation on the | operator is sparse, but my best guess is it only applies to the terms immediately before and after, which means, in effect, that OR takes precedence over AND (which is implicit; all terms are AND-ed by default). But in most cases this should not be an issue, and things work out OK in my experience.



            Give it a shot. I have found it surprisingly useful when it comes to browsing things when I am not really sure what I am looking for, and when context does not matter.






            share|improve this answer




























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "106"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f179238%2fgrep-inside-less%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              85














              less has very powerful pattern matching.  From the man page:




              &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.



                ____________
                Certain characters are special
                if entered at the beginning of the pattern;
                they modify the type of search
                rather than become part of the pattern.



                 (Of course ^N and ^R represent Ctrl+N
              and Ctrl+R, respectively.) 



              So, for example, &dns will display only lines that match the pattern dns,
              and &!dns will filter out (exclude) those lines,
              displaying only lines that don't match the pattern.



              It is noted in the description of the / command that




                The pattern is a regular expression,
                as recognized by the regular expression library supplied by your system.



              So





              • &eth[01]  will display lines containing eth0 or eth1


              • &arp.*eth0 will display lines containing arp followed by eth0


              • &arp|dns  will display lines containing arp or dns


              And the ! can invert any of the above. 
              So the command you would want to use for the example in your question is:



              &!event text|something else|the other thing|foo|bar


              Also use /pattern and ?pattern
              to search (and n/N to go to next/previous).






              share|improve this answer























              • 1





                This is almost there! In less, using '&!<1stpattern>' allows me to 'hide' lines with a pattern on, however it only applies to one pattern at a time, so if I find a second pattern and apply '&!<2ndpattern>', lines that matched the first pattern and were hidden, are now visible. So very close!

                – forquare
                Jan 15 '15 at 11:19











              • @forquare: There's a command history that you can access with the up & down arrows keys. So press &! and then press an arrow key.

                – PM 2Ring
                Jan 15 '15 at 11:34











              • @forquare: And I just discovered that the history is saved, so your old patterns will be available next time you run less; I don't know if it's preserved after rebooting, though.

                – PM 2Ring
                Jan 15 '15 at 11:40






              • 1





                @orion that was the last bit I was missing - how to concatenate patterns together. I though I had tried the pipe symbol before and it failed, but now I try again it works! So: &!<pattern1>|<pattern2>|<pattern3> will remove lines with pattern1 or pattern2 or pattern3

                – forquare
                Jan 15 '15 at 11:47






              • 1





                I figured it out. Homebrew dupes has the latest version. I just had to kick bash because it wasn't grabbing the right file (even though which told me it was grabbing /user/local/bin/less).

                – spinlock
                Mar 31 '15 at 20:17
















              85














              less has very powerful pattern matching.  From the man page:




              &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.



                ____________
                Certain characters are special
                if entered at the beginning of the pattern;
                they modify the type of search
                rather than become part of the pattern.



                 (Of course ^N and ^R represent Ctrl+N
              and Ctrl+R, respectively.) 



              So, for example, &dns will display only lines that match the pattern dns,
              and &!dns will filter out (exclude) those lines,
              displaying only lines that don't match the pattern.



              It is noted in the description of the / command that




                The pattern is a regular expression,
                as recognized by the regular expression library supplied by your system.



              So





              • &eth[01]  will display lines containing eth0 or eth1


              • &arp.*eth0 will display lines containing arp followed by eth0


              • &arp|dns  will display lines containing arp or dns


              And the ! can invert any of the above. 
              So the command you would want to use for the example in your question is:



              &!event text|something else|the other thing|foo|bar


              Also use /pattern and ?pattern
              to search (and n/N to go to next/previous).






              share|improve this answer























              • 1





                This is almost there! In less, using '&!<1stpattern>' allows me to 'hide' lines with a pattern on, however it only applies to one pattern at a time, so if I find a second pattern and apply '&!<2ndpattern>', lines that matched the first pattern and were hidden, are now visible. So very close!

                – forquare
                Jan 15 '15 at 11:19











              • @forquare: There's a command history that you can access with the up & down arrows keys. So press &! and then press an arrow key.

                – PM 2Ring
                Jan 15 '15 at 11:34











              • @forquare: And I just discovered that the history is saved, so your old patterns will be available next time you run less; I don't know if it's preserved after rebooting, though.

                – PM 2Ring
                Jan 15 '15 at 11:40






              • 1





                @orion that was the last bit I was missing - how to concatenate patterns together. I though I had tried the pipe symbol before and it failed, but now I try again it works! So: &!<pattern1>|<pattern2>|<pattern3> will remove lines with pattern1 or pattern2 or pattern3

                – forquare
                Jan 15 '15 at 11:47






              • 1





                I figured it out. Homebrew dupes has the latest version. I just had to kick bash because it wasn't grabbing the right file (even though which told me it was grabbing /user/local/bin/less).

                – spinlock
                Mar 31 '15 at 20:17














              85












              85








              85







              less has very powerful pattern matching.  From the man page:




              &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.



                ____________
                Certain characters are special
                if entered at the beginning of the pattern;
                they modify the type of search
                rather than become part of the pattern.



                 (Of course ^N and ^R represent Ctrl+N
              and Ctrl+R, respectively.) 



              So, for example, &dns will display only lines that match the pattern dns,
              and &!dns will filter out (exclude) those lines,
              displaying only lines that don't match the pattern.



              It is noted in the description of the / command that




                The pattern is a regular expression,
                as recognized by the regular expression library supplied by your system.



              So





              • &eth[01]  will display lines containing eth0 or eth1


              • &arp.*eth0 will display lines containing arp followed by eth0


              • &arp|dns  will display lines containing arp or dns


              And the ! can invert any of the above. 
              So the command you would want to use for the example in your question is:



              &!event text|something else|the other thing|foo|bar


              Also use /pattern and ?pattern
              to search (and n/N to go to next/previous).






              share|improve this answer















              less has very powerful pattern matching.  From the man page:




              &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.



                ____________
                Certain characters are special
                if entered at the beginning of the pattern;
                they modify the type of search
                rather than become part of the pattern.



                 (Of course ^N and ^R represent Ctrl+N
              and Ctrl+R, respectively.) 



              So, for example, &dns will display only lines that match the pattern dns,
              and &!dns will filter out (exclude) those lines,
              displaying only lines that don't match the pattern.



              It is noted in the description of the / command that




                The pattern is a regular expression,
                as recognized by the regular expression library supplied by your system.



              So





              • &eth[01]  will display lines containing eth0 or eth1


              • &arp.*eth0 will display lines containing arp followed by eth0


              • &arp|dns  will display lines containing arp or dns


              And the ! can invert any of the above. 
              So the command you would want to use for the example in your question is:



              &!event text|something else|the other thing|foo|bar


              Also use /pattern and ?pattern
              to search (and n/N to go to next/previous).







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Sep 3 '15 at 5:51









              G-Man

              15.2k9 gold badges44 silver badges82 bronze badges




              15.2k9 gold badges44 silver badges82 bronze badges










              answered Jan 15 '15 at 11:13









              orionorion

              9,64120 silver badges33 bronze badges




              9,64120 silver badges33 bronze badges











              • 1





                This is almost there! In less, using '&!<1stpattern>' allows me to 'hide' lines with a pattern on, however it only applies to one pattern at a time, so if I find a second pattern and apply '&!<2ndpattern>', lines that matched the first pattern and were hidden, are now visible. So very close!

                – forquare
                Jan 15 '15 at 11:19











              • @forquare: There's a command history that you can access with the up & down arrows keys. So press &! and then press an arrow key.

                – PM 2Ring
                Jan 15 '15 at 11:34











              • @forquare: And I just discovered that the history is saved, so your old patterns will be available next time you run less; I don't know if it's preserved after rebooting, though.

                – PM 2Ring
                Jan 15 '15 at 11:40






              • 1





                @orion that was the last bit I was missing - how to concatenate patterns together. I though I had tried the pipe symbol before and it failed, but now I try again it works! So: &!<pattern1>|<pattern2>|<pattern3> will remove lines with pattern1 or pattern2 or pattern3

                – forquare
                Jan 15 '15 at 11:47






              • 1





                I figured it out. Homebrew dupes has the latest version. I just had to kick bash because it wasn't grabbing the right file (even though which told me it was grabbing /user/local/bin/less).

                – spinlock
                Mar 31 '15 at 20:17














              • 1





                This is almost there! In less, using '&!<1stpattern>' allows me to 'hide' lines with a pattern on, however it only applies to one pattern at a time, so if I find a second pattern and apply '&!<2ndpattern>', lines that matched the first pattern and were hidden, are now visible. So very close!

                – forquare
                Jan 15 '15 at 11:19











              • @forquare: There's a command history that you can access with the up & down arrows keys. So press &! and then press an arrow key.

                – PM 2Ring
                Jan 15 '15 at 11:34











              • @forquare: And I just discovered that the history is saved, so your old patterns will be available next time you run less; I don't know if it's preserved after rebooting, though.

                – PM 2Ring
                Jan 15 '15 at 11:40






              • 1





                @orion that was the last bit I was missing - how to concatenate patterns together. I though I had tried the pipe symbol before and it failed, but now I try again it works! So: &!<pattern1>|<pattern2>|<pattern3> will remove lines with pattern1 or pattern2 or pattern3

                – forquare
                Jan 15 '15 at 11:47






              • 1





                I figured it out. Homebrew dupes has the latest version. I just had to kick bash because it wasn't grabbing the right file (even though which told me it was grabbing /user/local/bin/less).

                – spinlock
                Mar 31 '15 at 20:17








              1




              1





              This is almost there! In less, using '&!<1stpattern>' allows me to 'hide' lines with a pattern on, however it only applies to one pattern at a time, so if I find a second pattern and apply '&!<2ndpattern>', lines that matched the first pattern and were hidden, are now visible. So very close!

              – forquare
              Jan 15 '15 at 11:19





              This is almost there! In less, using '&!<1stpattern>' allows me to 'hide' lines with a pattern on, however it only applies to one pattern at a time, so if I find a second pattern and apply '&!<2ndpattern>', lines that matched the first pattern and were hidden, are now visible. So very close!

              – forquare
              Jan 15 '15 at 11:19













              @forquare: There's a command history that you can access with the up & down arrows keys. So press &! and then press an arrow key.

              – PM 2Ring
              Jan 15 '15 at 11:34





              @forquare: There's a command history that you can access with the up & down arrows keys. So press &! and then press an arrow key.

              – PM 2Ring
              Jan 15 '15 at 11:34













              @forquare: And I just discovered that the history is saved, so your old patterns will be available next time you run less; I don't know if it's preserved after rebooting, though.

              – PM 2Ring
              Jan 15 '15 at 11:40





              @forquare: And I just discovered that the history is saved, so your old patterns will be available next time you run less; I don't know if it's preserved after rebooting, though.

              – PM 2Ring
              Jan 15 '15 at 11:40




              1




              1





              @orion that was the last bit I was missing - how to concatenate patterns together. I though I had tried the pipe symbol before and it failed, but now I try again it works! So: &!<pattern1>|<pattern2>|<pattern3> will remove lines with pattern1 or pattern2 or pattern3

              – forquare
              Jan 15 '15 at 11:47





              @orion that was the last bit I was missing - how to concatenate patterns together. I though I had tried the pipe symbol before and it failed, but now I try again it works! So: &!<pattern1>|<pattern2>|<pattern3> will remove lines with pattern1 or pattern2 or pattern3

              – forquare
              Jan 15 '15 at 11:47




              1




              1





              I figured it out. Homebrew dupes has the latest version. I just had to kick bash because it wasn't grabbing the right file (even though which told me it was grabbing /user/local/bin/less).

              – spinlock
              Mar 31 '15 at 20:17





              I figured it out. Homebrew dupes has the latest version. I just had to kick bash because it wasn't grabbing the right file (even though which told me it was grabbing /user/local/bin/less).

              – spinlock
              Mar 31 '15 at 20:17













              6














              Building on orion's answer, the less(1) man page describes




              /pattern



                Search forward in the file for the N-th line
                containing the pattern. 
                N defaults to 1. 
                The pattern is a regular expression,
                as recognized by the regular expression library supplied by your system. 
                The search starts at the second line displayed
                (but see the -a and -j options, which change this).

                Certain characters are special
                if entered at the beginning of the pattern;
                they modify the type of search
                rather than become part of the pattern:



                ^N or !



                  Search for lines which do NOT match the pattern.

                ^E or *
                  Search multiple files. 
                  That is, if the search reaches the END of the current file
                  without finding a match,
                  the search continues in the next file in the command line list.

                ^F or @
                  Begin the search
                  at the first line of the FIRST file in the command line list,
                  regardless of what is currently displayed on the screen
                  or the settings of the -a or -j options.

                ^K

                  Highlight any text
                  which matches the pattern on the current screen,
                  but don't move to the first match (KEEP current position).

                ^R

                  Don't interpret regular expression metacharacters;
                  that is, do a simple textual comparison.



                ____________
                Commands may be preceded by a decimal number,
                called N in the descriptions …



                 (Of course ^N and ^E, etc., represent
              Ctrl+N and Ctrl+E, etc.) 



              It turns out that &pattern
              and /pattern work well together. 
              For example, the commands





              • &!arp|dnsEnter


              • /Ctrl+Kfail|fatal|fault|sd[a-z][0-9]Enter


              typed in either order, will hide (exclude) all lines
              containing arp or dns (like grep -v), and then, in the remaining lines,
              highlight all occurrences of fail, fatal, fault,
              or anything that looks like the name of a SCSI device (sd[a-z][0-9]). 
              Note that lines that contain arp or dns,
              and also fail or any of the other danger words,
              will not be displayed.






              share|improve this answer
































                6














                Building on orion's answer, the less(1) man page describes




                /pattern



                  Search forward in the file for the N-th line
                  containing the pattern. 
                  N defaults to 1. 
                  The pattern is a regular expression,
                  as recognized by the regular expression library supplied by your system. 
                  The search starts at the second line displayed
                  (but see the -a and -j options, which change this).

                  Certain characters are special
                  if entered at the beginning of the pattern;
                  they modify the type of search
                  rather than become part of the pattern:



                  ^N or !



                    Search for lines which do NOT match the pattern.

                  ^E or *
                    Search multiple files. 
                    That is, if the search reaches the END of the current file
                    without finding a match,
                    the search continues in the next file in the command line list.

                  ^F or @
                    Begin the search
                    at the first line of the FIRST file in the command line list,
                    regardless of what is currently displayed on the screen
                    or the settings of the -a or -j options.

                  ^K

                    Highlight any text
                    which matches the pattern on the current screen,
                    but don't move to the first match (KEEP current position).

                  ^R

                    Don't interpret regular expression metacharacters;
                    that is, do a simple textual comparison.



                  ____________
                  Commands may be preceded by a decimal number,
                  called N in the descriptions …



                   (Of course ^N and ^E, etc., represent
                Ctrl+N and Ctrl+E, etc.) 



                It turns out that &pattern
                and /pattern work well together. 
                For example, the commands





                • &!arp|dnsEnter


                • /Ctrl+Kfail|fatal|fault|sd[a-z][0-9]Enter


                typed in either order, will hide (exclude) all lines
                containing arp or dns (like grep -v), and then, in the remaining lines,
                highlight all occurrences of fail, fatal, fault,
                or anything that looks like the name of a SCSI device (sd[a-z][0-9]). 
                Note that lines that contain arp or dns,
                and also fail or any of the other danger words,
                will not be displayed.






                share|improve this answer






























                  6












                  6








                  6







                  Building on orion's answer, the less(1) man page describes




                  /pattern



                    Search forward in the file for the N-th line
                    containing the pattern. 
                    N defaults to 1. 
                    The pattern is a regular expression,
                    as recognized by the regular expression library supplied by your system. 
                    The search starts at the second line displayed
                    (but see the -a and -j options, which change this).

                    Certain characters are special
                    if entered at the beginning of the pattern;
                    they modify the type of search
                    rather than become part of the pattern:



                    ^N or !



                      Search for lines which do NOT match the pattern.

                    ^E or *
                      Search multiple files. 
                      That is, if the search reaches the END of the current file
                      without finding a match,
                      the search continues in the next file in the command line list.

                    ^F or @
                      Begin the search
                      at the first line of the FIRST file in the command line list,
                      regardless of what is currently displayed on the screen
                      or the settings of the -a or -j options.

                    ^K

                      Highlight any text
                      which matches the pattern on the current screen,
                      but don't move to the first match (KEEP current position).

                    ^R

                      Don't interpret regular expression metacharacters;
                      that is, do a simple textual comparison.



                    ____________
                    Commands may be preceded by a decimal number,
                    called N in the descriptions …



                     (Of course ^N and ^E, etc., represent
                  Ctrl+N and Ctrl+E, etc.) 



                  It turns out that &pattern
                  and /pattern work well together. 
                  For example, the commands





                  • &!arp|dnsEnter


                  • /Ctrl+Kfail|fatal|fault|sd[a-z][0-9]Enter


                  typed in either order, will hide (exclude) all lines
                  containing arp or dns (like grep -v), and then, in the remaining lines,
                  highlight all occurrences of fail, fatal, fault,
                  or anything that looks like the name of a SCSI device (sd[a-z][0-9]). 
                  Note that lines that contain arp or dns,
                  and also fail or any of the other danger words,
                  will not be displayed.






                  share|improve this answer















                  Building on orion's answer, the less(1) man page describes




                  /pattern



                    Search forward in the file for the N-th line
                    containing the pattern. 
                    N defaults to 1. 
                    The pattern is a regular expression,
                    as recognized by the regular expression library supplied by your system. 
                    The search starts at the second line displayed
                    (but see the -a and -j options, which change this).

                    Certain characters are special
                    if entered at the beginning of the pattern;
                    they modify the type of search
                    rather than become part of the pattern:



                    ^N or !



                      Search for lines which do NOT match the pattern.

                    ^E or *
                      Search multiple files. 
                      That is, if the search reaches the END of the current file
                      without finding a match,
                      the search continues in the next file in the command line list.

                    ^F or @
                      Begin the search
                      at the first line of the FIRST file in the command line list,
                      regardless of what is currently displayed on the screen
                      or the settings of the -a or -j options.

                    ^K

                      Highlight any text
                      which matches the pattern on the current screen,
                      but don't move to the first match (KEEP current position).

                    ^R

                      Don't interpret regular expression metacharacters;
                      that is, do a simple textual comparison.



                    ____________
                    Commands may be preceded by a decimal number,
                    called N in the descriptions …



                     (Of course ^N and ^E, etc., represent
                  Ctrl+N and Ctrl+E, etc.) 



                  It turns out that &pattern
                  and /pattern work well together. 
                  For example, the commands





                  • &!arp|dnsEnter


                  • /Ctrl+Kfail|fatal|fault|sd[a-z][0-9]Enter


                  typed in either order, will hide (exclude) all lines
                  containing arp or dns (like grep -v), and then, in the remaining lines,
                  highlight all occurrences of fail, fatal, fault,
                  or anything that looks like the name of a SCSI device (sd[a-z][0-9]). 
                  Note that lines that contain arp or dns,
                  and also fail or any of the other danger words,
                  will not be displayed.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Apr 13 '17 at 12:36









                  Community

                  1




                  1










                  answered Sep 1 '15 at 22:15









                  G-ManG-Man

                  15.2k9 gold badges44 silver badges82 bronze badges




                  15.2k9 gold badges44 silver badges82 bronze badges


























                      0














                      Over the last few months, I have become somewhat enamoured of fzf.



                      In your case, as long as context is not needed (i.e., the equivalent of grep's -A, -B, or -C is not needed, and by the way, less's & also has the same limitation), then fzf is a very powerful tool.



                      Here's a silly example:



                      printf "%sn" {aa,bb,cc}{dd,ee,ff}{gg,hh,ii} | fzf


                      If you run that, and play with inputs like aa | bb dd | ee !gg !hh and so on, you will quickly see what is happening.



                      Fzf's documentation on the | operator is sparse, but my best guess is it only applies to the terms immediately before and after, which means, in effect, that OR takes precedence over AND (which is implicit; all terms are AND-ed by default). But in most cases this should not be an issue, and things work out OK in my experience.



                      Give it a shot. I have found it surprisingly useful when it comes to browsing things when I am not really sure what I am looking for, and when context does not matter.






                      share|improve this answer






























                        0














                        Over the last few months, I have become somewhat enamoured of fzf.



                        In your case, as long as context is not needed (i.e., the equivalent of grep's -A, -B, or -C is not needed, and by the way, less's & also has the same limitation), then fzf is a very powerful tool.



                        Here's a silly example:



                        printf "%sn" {aa,bb,cc}{dd,ee,ff}{gg,hh,ii} | fzf


                        If you run that, and play with inputs like aa | bb dd | ee !gg !hh and so on, you will quickly see what is happening.



                        Fzf's documentation on the | operator is sparse, but my best guess is it only applies to the terms immediately before and after, which means, in effect, that OR takes precedence over AND (which is implicit; all terms are AND-ed by default). But in most cases this should not be an issue, and things work out OK in my experience.



                        Give it a shot. I have found it surprisingly useful when it comes to browsing things when I am not really sure what I am looking for, and when context does not matter.






                        share|improve this answer




























                          0












                          0








                          0







                          Over the last few months, I have become somewhat enamoured of fzf.



                          In your case, as long as context is not needed (i.e., the equivalent of grep's -A, -B, or -C is not needed, and by the way, less's & also has the same limitation), then fzf is a very powerful tool.



                          Here's a silly example:



                          printf "%sn" {aa,bb,cc}{dd,ee,ff}{gg,hh,ii} | fzf


                          If you run that, and play with inputs like aa | bb dd | ee !gg !hh and so on, you will quickly see what is happening.



                          Fzf's documentation on the | operator is sparse, but my best guess is it only applies to the terms immediately before and after, which means, in effect, that OR takes precedence over AND (which is implicit; all terms are AND-ed by default). But in most cases this should not be an issue, and things work out OK in my experience.



                          Give it a shot. I have found it surprisingly useful when it comes to browsing things when I am not really sure what I am looking for, and when context does not matter.






                          share|improve this answer













                          Over the last few months, I have become somewhat enamoured of fzf.



                          In your case, as long as context is not needed (i.e., the equivalent of grep's -A, -B, or -C is not needed, and by the way, less's & also has the same limitation), then fzf is a very powerful tool.



                          Here's a silly example:



                          printf "%sn" {aa,bb,cc}{dd,ee,ff}{gg,hh,ii} | fzf


                          If you run that, and play with inputs like aa | bb dd | ee !gg !hh and so on, you will quickly see what is happening.



                          Fzf's documentation on the | operator is sparse, but my best guess is it only applies to the terms immediately before and after, which means, in effect, that OR takes precedence over AND (which is implicit; all terms are AND-ed by default). But in most cases this should not be an issue, and things work out OK in my experience.



                          Give it a shot. I have found it surprisingly useful when it comes to browsing things when I am not really sure what I am looking for, and when context does not matter.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 41 mins ago









                          sitaramsitaram

                          814 bronze badges




                          814 bronze badges

































                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Unix & Linux Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f179238%2fgrep-inside-less%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                              Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                              Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...