grep中整字匹配

来源:互联网 发布:mac os x 启动盘 编辑:程序博客网 时间:2024/05/16 03:29
$ man grep


       -G, --basic-regexp
              Interpret PATTERN as a basic regular expression (BRE, see below).  This is the default.


       -P, --perl-regexp
              Interpret PATTERN as a Perl regular expression.  This is highly experimental and grep -P may
              warn of unimplemented features.


   Matching Control
       -e PATTERN, --regexp=PATTERN
              Use  PATTERN  as  the  pattern.  This can be used to specify multiple search patterns, or to
              protect a pattern beginning with a hyphen (-).  (-e is specified by POSIX.)


       -f FILE, --file=FILE
              Obtain patterns from FILE, one per  line.   The  empty  file  contains  zero  patterns,  and
              therefore matches nothing.  (-f is specified by POSIX.)


       -i, --ignore-case
              Ignore  case  distinctions  in  both  the  PATTERN and the input files.  (-i is specified by
              POSIX.)


       -v, --invert-match
              Invert the sense of matching, to select non-matching lines.  (-v is specified by POSIX.)


       -w, --word-regexp
              Select only those lines containing matches that form whole words.   The  test  is  that  the
              matching  substring  must  either be at the beginning of the line, or preceded by a non-word
              constituent character.  Similarly, it must be either at the end of the line or followed by a
              non-word  constituent  character.   Word-constituent characters are letters, digits, and the
              underscore.


       -x, --line-regexp
              Select only those matches that exactly match the whole line.  (-x is specified by POSIX.)


       -y     Obsolete synonym for -i.


   General Output Control

       -c, --count


查看man手册可以看到:

-w选项就是整字匹配

下面还有个-x选项是整行匹配


原创粉丝点击