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;
}
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
add a comment |
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
add a comment |
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
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
bash grep logs less
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
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
less
has very powerful pattern matching. From the man page:
&pattern
Display only lines which match thepattern
;
lines which do not match thepattern
are not displayed. Ifpattern
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 thepattern
.
^R
Don't interpret regular expression metacharacters;
that is, do a simple textual comparison.
____________
† Certain characters are special
if entered at the beginning of thepattern
;
they modify the type of search
rather than become part of thepattern
.
(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
ð[01]
will display lines containingeth0
oreth1
&arp.*eth0
will display lines containingarp
followed byeth0
&arp|dns
will display lines containingarp
ordns
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).
1
This is almost there! Inless
, 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 runless
; 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
|
show 4 more comments
Building on orion's answer, the less(1)
man page describes
/pattern
Search forward in the file for the N-th line
containing thepattern
.
N † defaults to 1.
Thepattern
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 thepattern
;
they modify the type of search
rather than become part of thepattern
:
^N
or!
Search for lines which do NOT match thepattern
.
^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 thepattern
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|dns
Enter
/
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.
add a comment |
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
less
has very powerful pattern matching. From the man page:
&pattern
Display only lines which match thepattern
;
lines which do not match thepattern
are not displayed. Ifpattern
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 thepattern
.
^R
Don't interpret regular expression metacharacters;
that is, do a simple textual comparison.
____________
† Certain characters are special
if entered at the beginning of thepattern
;
they modify the type of search
rather than become part of thepattern
.
(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
ð[01]
will display lines containingeth0
oreth1
&arp.*eth0
will display lines containingarp
followed byeth0
&arp|dns
will display lines containingarp
ordns
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).
1
This is almost there! Inless
, 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 runless
; 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
|
show 4 more comments
less
has very powerful pattern matching. From the man page:
&pattern
Display only lines which match thepattern
;
lines which do not match thepattern
are not displayed. Ifpattern
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 thepattern
.
^R
Don't interpret regular expression metacharacters;
that is, do a simple textual comparison.
____________
† Certain characters are special
if entered at the beginning of thepattern
;
they modify the type of search
rather than become part of thepattern
.
(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
ð[01]
will display lines containingeth0
oreth1
&arp.*eth0
will display lines containingarp
followed byeth0
&arp|dns
will display lines containingarp
ordns
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).
1
This is almost there! Inless
, 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 runless
; 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
|
show 4 more comments
less
has very powerful pattern matching. From the man page:
&pattern
Display only lines which match thepattern
;
lines which do not match thepattern
are not displayed. Ifpattern
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 thepattern
.
^R
Don't interpret regular expression metacharacters;
that is, do a simple textual comparison.
____________
† Certain characters are special
if entered at the beginning of thepattern
;
they modify the type of search
rather than become part of thepattern
.
(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
ð[01]
will display lines containingeth0
oreth1
&arp.*eth0
will display lines containingarp
followed byeth0
&arp|dns
will display lines containingarp
ordns
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).
less
has very powerful pattern matching. From the man page:
&pattern
Display only lines which match thepattern
;
lines which do not match thepattern
are not displayed. Ifpattern
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 thepattern
.
^R
Don't interpret regular expression metacharacters;
that is, do a simple textual comparison.
____________
† Certain characters are special
if entered at the beginning of thepattern
;
they modify the type of search
rather than become part of thepattern
.
(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
ð[01]
will display lines containingeth0
oreth1
&arp.*eth0
will display lines containingarp
followed byeth0
&arp|dns
will display lines containingarp
ordns
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).
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! Inless
, 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 runless
; 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
|
show 4 more comments
1
This is almost there! Inless
, 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 runless
; 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
|
show 4 more comments
Building on orion's answer, the less(1)
man page describes
/pattern
Search forward in the file for the N-th line
containing thepattern
.
N † defaults to 1.
Thepattern
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 thepattern
;
they modify the type of search
rather than become part of thepattern
:
^N
or!
Search for lines which do NOT match thepattern
.
^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 thepattern
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|dns
Enter
/
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.
add a comment |
Building on orion's answer, the less(1)
man page describes
/pattern
Search forward in the file for the N-th line
containing thepattern
.
N † defaults to 1.
Thepattern
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 thepattern
;
they modify the type of search
rather than become part of thepattern
:
^N
or!
Search for lines which do NOT match thepattern
.
^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 thepattern
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|dns
Enter
/
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.
add a comment |
Building on orion's answer, the less(1)
man page describes
/pattern
Search forward in the file for the N-th line
containing thepattern
.
N † defaults to 1.
Thepattern
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 thepattern
;
they modify the type of search
rather than become part of thepattern
:
^N
or!
Search for lines which do NOT match thepattern
.
^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 thepattern
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|dns
Enter
/
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.
Building on orion's answer, the less(1)
man page describes
/pattern
Search forward in the file for the N-th line
containing thepattern
.
N † defaults to 1.
Thepattern
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 thepattern
;
they modify the type of search
rather than become part of thepattern
:
^N
or!
Search for lines which do NOT match thepattern
.
^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 thepattern
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|dns
Enter
/
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.
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
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered 41 mins ago
sitaramsitaram
814 bronze badges
814 bronze badges
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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