Suppose I want to know the usage of -i
switch in grep
command without scrolling. I need the specification just for that command or at least see the screen show that first. So how? As you can say that in general not just for grep -i
.
Suppose I want to know the usage of -i
switch in grep
command without scrolling. I need the specification just for that command or at least see the screen show that first. So how? As you can say that in general not just for grep -i
.
Type the below command on terminal:
Then type slash character, /, and write your search, like
-i
, followed by Enter. This will position the cursor at the first occurrence of the search string. Pressing n moves the cursor to the next occurrence. Pressing Shift+n moves the cursor to the previous occurrence.Try this simple
sed
command,Explanation:
It will print the line which contains the search pattern along with 2 lines which present just below to the search pattern line.
OR
You can simply give only the flags in the search patten like below.
You can add this script to your
.bashrc
($HOME/.bashrc
) for quick access:While the simplest approach is to search with / as suggested by @girardengo, you can also use
grep
instead ofsed
which I find simpler:The
-A N
means "Print N lines after the matching one. Just a trick to get the next few lines, similar to Avinash'ssed
approach.You can use the search function inside
man
, just pres"s"
, type the key you're looking for, (-i in your case) and press intro.Or, you can let this site do the searching for you:
http://explainshell.com/explain?cmd=grep+-i
You have to switch from using the terminal to a browser for a bit, but there's ways around that too.
The most efficient method I am aware of is to search the man page for
-i
(This site seems to fail to render my code. What I mean is<space><space><space>-i
). That's 3 spaces (you may need more/less spaces) followed by the flag you're looking for. It almost always works in my experience, and you can change to some variant of it in cases where it doesn't work.It works because the actual documentation of the flags are typically indented. It avoids finding other mentions of the flag in other sections, because there's usually only one space before them.
Through all answers may be fine, but I think you are focusing in only a piece of documentation, not all. For example, to find the
-i
switch of the grep documentation:I will find all the information about "grep", how to "invoke" the specific "command-line options" for "matching control". Sadly it doesn't go more deeper than that, but it has
-i
,-y
,--ignore-case
in the firsts 25 lines, something reasonable that you don't have to scroll all your way down.This solution is the more flexible and also allows you to search all the infopages:
(had to use
--ignore-case
instead of-i
since it was too common, but you can just process the output to info in any case)In this case, you have both the name of the info page and the exact section. Ah, almost forgot, you can also just tab your way through most section of the info pages.
You can use Perl and its "paragraph mode" to extract only the relevant paragraph:
My favorite approach to find a given option in a
man
page is to use a regex like\s{2,}-option
. For the question in hand, you can doman grep
and then type the regex:or
This will match
-i
only when followed by three or more spaces.If you want to
grep
theman <program>
results for a pattern beginning with a hyphen, use--
before the pattern you specify.--
is a flag that most programs interpret as "nothing after this should be taken as a flag". Example usingman find
:If you want more info, for example the entire section describing an option, try using
sed
:Source