Try this simple sed
command,
$ man grep | sed -n '/-i, --ignore-case/,+2p'
-i, --ignore-case
Ignore case distinctions in both the PATTERN and the input
files. (-i is specified by POSIX.)
Explanation:
sed -n '/-i, --ignore-case/,+2p'
|<-Search pattern->|
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.
avinash@avinash-Lenovo-IdeaPad-Z500:~$ man grep | sed -n '/ *i, -/,+3p'
-i, --ignore-case
Ignore case distinctions in both the PATTERN and the input
files. (-i is specified by POSIX.)
avinash@avinash-Lenovo-IdeaPad-Z500:~$ man grep | sed -n '/ *V, -/,+3p'
-V, --version
Print the version number of grep to the standard output stream.
This version number should be included in all bug reports (see
below).
avinash@avinash-Lenovo-IdeaPad-Z500:~$ man grep | sed -n '/ *F, -/,+3p'
-F, --fixed-strings
Interpret PATTERN as a list of fixed strings, separated by
newlines, any of which is to be matched. (-F is specified by
POSIX.)
avinash@avinash-Lenovo-IdeaPad-Z500:~$ man grep | sed -n '/ *G, -/,+3p'
-G, --basic-regexp
Interpret PATTERN as a basic regular expression (BRE, see
below). This is the default.
You can add this script to your .bashrc
($HOME/.bashrc
) for quick access:
mangrep(){
USAGE="mangrep <application> <switch>"
if [[ "$#" -ne "2" ]]
then
echo "Usage: $USAGE"
else
man "$1" | sed -n "/ *"$2", -/,+3p"
fi
}
Best Answer
There isn't one as far as I know. You have a few choices though:
Pipe the output through
less
ormore
Hit the up until you find the command you ran and run it again (optionally using
less
ormore
again).Run the previous command through
less
using history expansion.Use a terminal that supports searching through the scroll back. The image below is showing my preferred terminal,
terminator
(installable withsudo apt-get terminator
) but Ubuntu's default terminal also supports this. Just hit Ctrl Shift F to show the search bar. If you then search for either the command's name or your username (which appears in your prompt) you will be taken directly back to the last command: