基本用法:
grep -c user file1 file2 只列印檔案中匹配的行數
grep -n user file1 file2 列印檔案中匹配的內容並顯示行號
grep -vc user file1 file2 列印出file1和file2不包含user的行數
grep -i user file1 file2 列印出file1和file2中包含user的行,並且不區分大小寫
grep -h user file1 file2 列印出file1和file2中包含user的行,只是不顯示檔名
grep -l user file1 file2 列印file1和file2中包含user的檔名
grep -r user * 列印出包含user的檔名和行內容,不對子目錄同樣檢索
grep -w user* file1 file2 -w引數遮蔽了元字元,表示搜尋user*
grep -w 『word』 * 嚴格匹配,只查詢包含word的行
與正規表示式一起使用
grep ^- file1 列印以-開頭的行
grep ^$ file1 列印空白行
grep [cc]aaa file 搜尋caaa和caaa
grep ^/..../* file 搜尋/開頭,/*結尾、並且中間有四個字元的行
grep '\-\' * -出現5次的地方
grep \精確匹配
精華 Grep 用法
grep g globally search for a re regular expression and p print the results.1 引數 i 忽略大小寫 c 列印匹配的行數 l 從多個檔案中查詢包含匹配項 v 查詢不包含匹配項的行 n 列印包含匹配項的行和行標 2 re 正規表...
grep 詳細用法
grep命令是unix中用於文字搜尋的大師級工具。搜到結果。如在檔案中搜尋乙個單詞 grep match pattern filename 或者 grep match pattern filename 也可以像下面這樣從stdin中讀取 echo e this is a word nnextline...
grep用法總結
grep,egrep,fgrep grep 根據模式搜尋文字,並將符合模式的文字行顯示出來 pattern 文字字元和正則表達的元字元組合而成匹配條件。grep options pattern file.i 忽略大小寫 colour v 顯示沒有被模式匹配到的行 o 只顯示被模式匹配到的字串 e 來...