RE字符 意義與範例
^word 待搜尋的字串(word)在行首。
word$ 待搜尋的字串(word)在行尾。
. 代表『任意一個』字符,一定是一個任意字符。
\ 跳脫字符,將特殊符號的特殊意義去除。
* 重複零個或多個的前一個 RE 字符
\{n,m\} 連續 n 到 m 個的『前一個 RE 字符』
若為 \{n\} 則是連續 n 個的前一個 RE 字符,
若是 \{n,\} 則是連續 n 個以上的前一個 RE 字符。
[ ] 在 [ ] 當中『僅代表一個待搜尋的字元』
若 [^],^ 在中括號中表示 NOT。
[dywang@dywmac ~]$ grep -n ^C /etc/man.config 108:CAT /bin/cat 114:CMP /usr/libexec/man-cmp.sh 118:COMPRESS /usr/bin/lzma 119:COMPRESS_EXT .lzma
s.。
[dywang@dywmac ~]$ grep -n 's\.$' /etc/man.config 37:# and to determine the correspondence between extensions and decompressors. 63:# lots of other nearby files and directories. 144:# Enable/disable makewhatis database cron updates.
# 且只有這個註解符號,共有 34 行。
[dywang@dywmac ~]$ grep '^#$' /etc/man.config | wc -l 34
# 的行數,也就是不是註解的行,共有 39 行。
[dywang@dywmac ~]$ grep -v '^#' /etc/man.config | wc -l 113
[dywang@dywmac ~]$ grep -n 'C[HM]' /etc/man.config
80:# NOCACHE keeps man from creating cache pages ("cat pages")
84:#NOCACHE
111:# When CMP is defined man will try to avoid showing the same
114:CMP /usr/libexec/man-cmp.sh
[dywang@dywmac ~]$ grep -n '^C[^HM]' /etc/man.config 108:CAT /bin/cat 118:COMPRESS /usr/bin/lzma 119:COMPRESS_EXT .lzma
[dywang@dywmac ~]$ grep '[0-9][a-zA-Z][a-zA-Z]*' /etc/man.config # man.conf from man-1.6f MANPATH /usr/X11R6/man MANPATH_MAP /usr/X11R6/bin /usr/X11R6/man MANPATH_MAP /usr/bin/X11 /usr/X11R6/man # and the MANSECT environment variable is not set (1x-8x sections are used by MANSECT 1:1p:8:2:3:3p:4:5:6:7:9:0p:n:l:p:o:1x:2x:3x:4x:5x:6x:7x:8x
[dywang@dywmac ~]$ grep '[a-zA-Z]\{12,15\}' /etc/man.config
# Generated automatically from man.conf.in by the
# pages corresponding to given man pages should be stored,
# MANPATH manpath_element [corresponding_catdir]
# and to determine the correspondence between extensions and decompressors.
# Every automatically generated MANPATH includes these fields
# NOAUTOPATH keeps man from automatically adding directories that look like
#MANDEFOPTIONS -a
# Decompress with given decompressor when input file has given extension
# If MAKEWHATISDBUPDATES variable is uncommented
#MAKEWHATISDBUPDATES n
[dywang@dywmac ~]$ grep '[a-zA-Z]\{14,\}' /etc/man.config
# and to determine the correspondence between extensions and decompressors.
# If MAKEWHATISDBUPDATES variable is uncommented
#MAKEWHATISDBUPDATES n
[dywang@dywmac ~]$ grep '[^a-zA-Z][a-zA-Z]\{13\}[^a-zA-Z]' /etc/man.config
# Generated automatically from man.conf.in by the
# pages corresponding to given man pages should be stored,
# MANPATH manpath_element [corresponding_catdir]
# and to determine the correspondence between extensions and decompressors.
# Every automatically generated MANPATH includes these fields
# NOAUTOPATH keeps man from automatically adding directories that look like
#MANDEFOPTIONS -a
[dywang@dywmac ~]$ grep 'x.*y' /etc/man.config # Explicitly given catdirs override. # The command "man -a xyzzy" will show all man pages for xyzzy. # and the MANSECT environment variable is not set (1x-8x sections are used by
[root@dywssd bin]# grep 'this\|will' /etc/man.config # For more information about this file, see the man pages man(1) # (so that this dir has both man1 etc. and cat1 etc. subdirs). # The keyword FSSTND will cause this behaviour. # The keyword FHS will cause this behaviour (and overrides FSSTND). # in the mandatory manpath already, but will keep man from statting # The command "man -a xyzzy" will show all man pages for xyzzy. # When CMP is defined man will try to avoid showing the same # will not update makewhatis database. # Otherwise the database will be updated.