Coba sed
perintah sederhana ini ,
$ 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.)
Penjelasan:
sed -n '/-i, --ignore-case/,+2p'
|<-Search pattern->|
Ini akan mencetak garis yang berisi pola pencarian bersama dengan 2 baris yang hadir tepat di bawah ke garis pola pencarian.
ATAU
Anda cukup memberikan hanya flag di patten pencarian seperti di bawah ini.
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.
Anda dapat menambahkan skrip ini ke .bashrc
( $HOME/.bashrc
) Anda untuk akses cepat:
mangrep(){
USAGE="mangrep <application> <switch>"
if [[ "$#" -ne "2" ]]
then
echo "Usage: $USAGE"
else
man "$1" | sed -n "/ *"$2", -/,+3p"
fi
}