grep 同時知足多個關鍵字和知足任意關鍵字

grep 同時知足多個關鍵字和知足任意關鍵字
① grep -E "word1|word2|word3"   file.txt
   知足任意條件(word一、word2和word3之一)將匹配。
② grep word1 file.txt | grep word2 |grep word3
   必須同時知足三個條件(word一、word2和word3)才匹配。
 
 
其實這很好理解,只是我平時沒有用多個關鍵字搜索過,一會兒有點蒙,平時遇到也是先度娘,哈哈哈哈哈,哎
 
grep keyword filename  |  grep keyword2
前一段多搜索結果  經過管道到另外一邊 在查詢頗有關鍵字keyword2到
 
卻是知足任何一個關鍵字到, -E命令要記一下
 

 

 

-E, --extended-regexpexpress

             Interpret pattern as an extended regular expression (i.e. forcespa

             grep to behave as egrep).regexp

 

     -e pattern, --regexp=patternblog

             Specify a pattern used during the search of the input: an inputip

             line is selected if it matches any of the specified patterns.ci

             This option is most useful when multiple -e options are used toinput

             specify multiple patterns, or when a pattern begins with a dashstring

             (`-').it

 

     --excludeio

             If specified, it excludes files matching the given filename pat-

             tern from the search.  Note that --exclude patterns take priority

             over --include patterns, and if no --include pattern is speci-

             fied, all files are searched that are not excluded.  Patterns are

             matched to the full path specified, not only to the filename com-

             ponent.

 

     --exclude-dir

             If -R is specified, it excludes directories matching the given

             filename pattern from the search.  Note that --exclude-dir pat-

             terns take priority over --include-dir patterns, and if no

             --include-dir pattern is specified, all directories are searched

             that are not excluded.

 

     -F, --fixed-strings

             Interpret pattern as a set of fixed strings (i.e. force grep to

             behave as fgrep).

 

     -f file, --file=file

             Read one or more newline separated patterns from file.  Empty

             pattern lines match every input line.  Newlines are not consid-

             ered part of a pattern.  If file is empty, nothing is matched.

相關文章
相關標籤/搜索