grep vivek \/etc\/passwd\r\n<\/pre>\n\u8f93\u51fa\u4f8b\u5b50:<\/p>\n
vivek:x:1000:1000:Vivek Gite,,,:\/home\/vivek:\/bin\/bash\r\nvivekgite:x:1001:1001::\/home\/vivekgite:\/bin\/sh\r\ngitevivek:x:1002:1002::\/home\/gitevivek:\/bin\/sh\r\n<\/pre>\n\u641c\u7d22\u5927\u5c0f\u5199\u4efb\u610f\u7684 vivek(\u5373\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u7684\u641c\u7d22)<\/p>\n
grep -i -w vivek \/etc\/passwd\r\n<\/pre>\n\u641c\u7d22\u5927\u5c0f\u5199\u4efb\u610f\u7684 vivek \u6216 raj<\/p>\n
grep -E -i -w 'vivek|raj' \/etc\/passwd\r\n<\/pre>\n\u4e0a\u9762\u6700\u540e\u7684\u4f8b\u5b50\u663e\u793a\u7684\uff0c\u5c31\u662f\u4e00\u4e2a\u6269\u5c55\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u6a21\u5f0f\u3002<\/p>\n
\u951a\u70b9<\/strong><\/div>\n\u4f60\u53ef\u4ee5\u5206\u522b\u4f7f\u7528 ^ \u548c $ \u7b26\u53f7\u6765\u6b63\u5219\u5339\u914d\u8f93\u5165\u884c\u7684\u5f00\u59cb\u6216\u7ed3\u5c3e\u3002\u4e0b\u9762\u7684\u4f8b\u5b50\u641c\u7d22\u663e\u793a\u4ec5\u4ec5\u4ee5 vivek \u5f00\u59cb\u7684\u8f93\u5165\u884c\uff1a<\/p>\n
grep ^vivek \/etc\/passwd\r\n<\/pre>\n\u8f93\u51fa\u4f8b\u5b50:<\/p>\n
vivek:x:1000:1000:Vivek Gite,,,:\/home\/vivek:\/bin\/bash\r\nvivekgite:x:1001:1001::\/home\/vivekgite:\/bin\/sh\r\n<\/pre>\n\u4f60\u53ef\u4ee5\u4ec5\u4ec5\u53ea\u641c\u7d22\u51fa\u4ee5\u5355\u8bcd vivek \u5f00\u59cb\u7684\u884c\uff0c\u5373\u4e0d\u663e\u793a vivekgit\u3001vivekg \u7b49\uff08LCTT \u8bd1\u6ce8\uff1a\u5373\u8be5\u5355\u8bcd\u540e\u9762\u662f\u7a7a\u683c\u3001\u7b26\u53f7\u7b49\u82f1\u6587\u7684\u5355\u8bcd\u5206\u9694\u7b26\u3002\uff09<\/p>\n
grep -w ^vivek \/etc\/passwd\r\n<\/pre>\n\u627e\u51fa\u4ee5\u5355\u8bcd word \u7ed3\u5c3e\u7684\u884c\uff1a<\/p>\n
grep 'foo$' \u6587\u4ef6\u540d\r\n<\/pre>\n\u5339\u914d\u4ec5\u4ec5\u53ea\u5305\u542b foo \u7684\u884c\uff1a<\/p>\n
grep '^foo$' \u6587\u4ef6\u540d\r\n<\/pre>\n\u5982\u4e0b\u6240\u793a\u7684\u4f8b\u5b50\u53ef\u4ee5\u641c\u7d22\u7a7a\u884c\uff1a<\/p>\n
grep '^$' \u6587\u4ef6\u540d\r\n<\/pre>\n\u5b57\u7b26\u7c7b<\/strong><\/div>\n\u5339\u914d Vivek \u6216 vivek\uff1a<\/p>\n
grep '[vV]ivek' \u6587\u4ef6\u540d\r\n<\/pre>\n\u6216\u8005<\/p>\n
grep '[vV][iI][Vv][Ee][kK]' \u6587\u4ef6\u540d\r\n<\/pre>\n\u4e5f\u53ef\u4ee5\u5339\u914d\u6570\u5b57 (\u5373\u5339\u914d vivek1 \u6216 Vivek2 \u7b49\u7b49):<\/p>\n
grep -w '[vV]ivek[0-9]' \u6587\u4ef6\u540d\r\n<\/pre>\n\u53ef\u4ee5\u5339\u914d\u4e24\u4e2a\u6570\u5b57\u5b57\u7b26(\u5373 foo11\u3001foo12 \u7b49):<\/p>\n
grep 'foo[0-9][0-9]' \u6587\u4ef6\u540d\r\n<\/pre>\n\u4e0d\u4ec5\u4ec5\u5c40\u9650\u4e8e\u6570\u5b57\uff0c\u4e5f\u80fd\u5339\u914d\u81f3\u5c11\u4e00\u4e2a\u5b57\u6bcd\u7684:<\/p>\n
grep '[A-Za-z]' \u6587\u4ef6\u540d\r\n<\/pre>\n\u663e\u793a\u542b\u6709 \"w\" \u6216 \"n\" \u5b57\u7b26\u7684\u6240\u6709\u884c\uff1a<\/p>\n
grep [wn] \u6587\u4ef6\u540d\r\n<\/pre>\n\u653e\u5728\u62ec\u53f7\u5185\u7684\u8868\u8fbe\u5f0f\uff0c\u5373\u5305\u5728 \"[:\" \u548c \":]\" \u4e4b\u95f4\u7684\u5b57\u7b26\u7c7b\u7684\u540d\u5b57\uff0c\u5b83\u8868\u793a\u7684\u662f\u5c5e\u4e8e\u6b64\u7c7b\u7684\u6240\u6709\u5b57\u7b26\u5217\u8868\u3002\u6807\u51c6\u7684\u5b57\u7b26\u7c7b\u540d\u79f0\u5982\u4e0b\uff1a<\/p>\n
[:alnum:]<\/pre>\n- \u5b57\u6bcd\u6570\u5b57\u5b57\u7b26<\/p>\n
[:alpha:]<\/pre>\n- \u5b57\u6bcd\u5b57\u7b26<\/p>\n
[:blank:]<\/pre>\n- \u7a7a\u5b57\u7b26: \u7a7a\u683c\u952e\u7b26 \u548c \u5236\u8868\u7b26<\/p>\n
[:digit:]<\/pre>\n- \u6570\u5b57: '0 1 2 3 4 5 6 7 8 9'<\/p>\n
[:lower:]<\/pre>\n- \u5c0f\u5199\u5b57\u6bcd: 'a b c d e f g h i j k l m n o p q r s t u v w x y z'<\/p>\n
[:space:]<\/pre>\n- \u7a7a\u683c\u5b57\u7b26: \u5236\u8868\u7b26\u3001\u6362\u884c\u7b26\u3001\u5782\u76f4\u5236\u8868\u7b26\u3001\u6362\u9875\u7b26\u3001\u56de\u8f66\u7b26\u548c\u7a7a\u683c\u952e\u7b26<\/p>\n
[:upper:]<\/pre>\n- \u5927\u5199\u5b57\u6bcd: 'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z'<\/p>\n
\u5728\u8fd9\u4e2a\u4f8b\u5b50\u6240\u793a\u7684\u662f\u5339\u914d\u6240\u6709\u5927\u5199\u5b57\u6bcd:<\/p>\n
grep '[:upper:]' \u6587\u4ef6\u540d\r\n<\/pre>\n\u901a\u914d\u7b26<\/strong><\/div>\n\u4f60\u53ef\u4ee5\u4f7f\u7528 \".\" \u6765\u5339\u914d\u5355\u4e2a\u5b57\u7b26\u3002\u4f8b\u5b50\u4e2d\u5339\u914d\u4ee5 \"b\" \u5f00\u5934\u4ee5 \"t\" \u7ed3\u5c3e\u76843\u4e2a\u5b57\u7b26\u7684\u5355\u8bcd\uff1a<\/p>\n
grep '\/<b.t\/>' \u6587\u4ef6\u540d\r\n<\/pre>\n\u5728\u8fd9\u513f,<\/p>\n
\u5339\u914d\u5355\u8bcd\u524d\u9762\u7684\u7a7a\u5b57\u7b26\u4e32
\n\u5339\u914d\u5355\u8bcd\u540e\u9762\u7684\u7a7a\u5b57\u7b26\u4e32<\/p>\n
\u6253\u5370\u51fa\u53ea\u6709\u4e24\u4e2a\u5b57\u7b26\u7684\u6240\u6709\u884c:<\/p>\n
grep '^..$' \u6587\u4ef6\u540d\r\n<\/pre>\n\u663e\u793a\u4ee5\u4e00\u4e2a\u70b9\u548c\u4e00\u4e2a\u6570\u5b57\u5f00\u5934\u7684\u884c\uff1a<\/p>\n
grep '^\/.[0-9]' \u6587\u4ef6\u540d\r\n<\/pre>\n\u70b9\u5b57\u7b26\u8f6c\u4e49<\/strong><\/div>\n\u4e0b\u9762\u8981\u5339\u914d\u5230 IP \u5730\u5740\u4e3a 192.168.1.254 \u7684\u6b63\u5219\u5f0f\u662f\u4e0d\u6b63\u786e\u7684\uff1a\uff08LCTT \u8bd1\u6ce8\uff1a\u53ef\u4ee5\u5339\u914d\u5230\u8be5 IP \u5730\u5740\uff0c\u4f46\u662f\u4e5f\u6709\u53ef\u80fd\u5339\u914d\u5230\u95f4\u9694\u7b26\u53f7\u4e0d\u662f\u70b9\u7684\u7c7b\u4f3c\u683c\u5f0f\uff09<\/p>\n
grep '192.168.1.254' \/etc\/hosts\r\n<\/pre>\n\u4e09\u4e2a\u70b9\u5b57\u7b26\u90fd\u9700\u8981\u8f6c\u4e49\uff1a<\/p>\n
grep '192\/.168\/.1\/.254' \/etc\/hosts\r\n<\/pre>\n\u4e0b\u9762\u7684\u4f8b\u5b50\u53ea\u80fd\u5339\u914d\u51fa IP \u5730\u5740\uff1a\uff08LCTT \u8bd1\u6ce8\uff1a\u5b9e\u9645\u4e0a\u7531\u4e8e IP \u5730\u5740\u4e2d\u6570\u5b57\u7684\u53d6\u503c\u8303\u56f4\uff0c\u8be5\u6b63\u5219\u8868\u8fbe\u5f0f\u5e76\u4e0d\u7cbe\u786e\uff09<\/p>\n
egrep '[[:digit:]]{1,3}\/.[[:digit:]]{1,3}\/.[[:digit:]]{1,3}\/.[[:digit:]]{1,3}' \u6587\u4ef6\u540d\r\n<\/pre>\n\u600e\u4e48\u6837\u641c\u7d22\u4ee5\u201c-\u201d \u7b26\u53f7\u5f00\u5934\u7684\u5339\u914d\u6a21\u5f0f\uff1f<\/strong><\/span><\/div>\n\u8981\u4f7f\u7528 -e \u9009\u9879\u6765\u641c\u7d22\u5339\u914d '--test--' \u5b57\u7b26\u4e32\uff0c\u5982\u679c\u4e0d\u4f7f\u7528 -e \u9009\u9879\uff0cgrep \u547d\u4ee4\u4f1a\u8bd5\u56fe\u628a '--test--' \u5f53\u4f5c\u81ea\u5df1\u7684\u9009\u9879\u53c2\u6570\u6765\u89e3\u6790\uff1a<\/p>\n
grep -e '--test--' \u6587\u4ef6\u540d\r\n<\/pre>\n\u600e\u4e48\u4f7f\u7528 grep \u7684\u201c\u6216\u201d\u5339\u914d?<\/strong><\/span><\/div>\n\u4f7f\u7528\u5982\u4e0b\u7684\u8bed\u6cd5\uff1a<\/p>\n
grep -E 'word1|word2' \u6587\u4ef6\u540d\r\n\u6216\r\negrep 'word1|word2' \u6587\u4ef6\u540d\r\n<\/pre>\n\u6216\u8005\u662f<\/p>\n
grep 'word1\/|word2' \u6587\u4ef6\u540d\r\n<\/pre>\n\u600e\u4e48\u4f7f\u7528 grep \u7684\u201c\u548c\u201d\u5339\u914d?<\/strong><\/span><\/div>\n\u4f7f\u7528\u4e0b\u9762\u7684\u8bed\u6cd5\u6765\u663e\u793a\u65e2\u5305\u542b 'word1' \u53c8\u5305\u542b 'word2' \u7684\u6240\u6709\u884c<\/p>\n
grep 'word1' \u6587\u4ef6\u540d | grep 'word2'\r\n<\/pre>\n\u600e\u4e48\u6837\u4f7f\u7528\u5e8f\u5217\u68c0\u6d4b?<\/strong><\/span><\/div>\n\u4f7f\u7528\u5982\u4e0b\u7684\u8bed\u6cd5\uff0c\u60a8\u53ef\u4ee5\u68c0\u6d4b\u4e00\u4e2a\u5b57\u7b26\u5728\u5e8f\u5217\u4e2d\u91cd\u590d\u51fa\u73b0\u6b21\u6570\uff1a<\/p>\n
{N}\r\n{N,}\r\n{min,max}\r\n<\/pre>\n\u8981\u5339\u914d\u5b57\u7b26 \u201cv\" \u51fa\u73b0\u4e24\u6b21\uff1a<\/p>\n
egrep \"v{2}\" \u6587\u4ef6\u540d\r\n<\/pre>\n\u4e0b\u9762\u7684\u547d\u4ee4\u80fd\u5339\u914d\u5230 \"col\" \u548c \"cool\" \uff1a<\/p>\n
egrep 'co{1,2}l' \u6587\u4ef6\u540d\r\n<\/pre>\n\u4e0b\u9762\u7684\u547d\u4ee4\u5c06\u4f1a\u5339\u914d\u51fa\u81f3\u5c11\u6709\u4e09\u4e2a 'c' \u5b57\u7b26\u7684\u6240\u6709\u884c\u3002<\/p>\n
egrep 'c{3,}' \u6587\u4ef6\u540d\r\n<\/pre>\n\u4e0b\u9762\u7684\u4f8b\u5b50\u4f1a\u5339\u914d 91-1234567890\uff08\u5373\u4e8c\u4e2a\u6570\u5b57-\u5341\u4e2a\u6570\u5b57\uff09 \u8fd9\u79cd\u683c\u5f0f\u7684\u624b\u673a\u53f7\u3002<\/p>\n
grep \"[[:digit:]]\/{2\/}[ -]\/?[[:digit:]]\/{10\/}\" \u6587\u4ef6\u540d\r\n<\/pre>\n\u600e\u4e48\u6837\u4f7f grep \u547d\u4ee4\u9ad8\u4eae\u663e\u793a\uff1f<\/strong><\/span><\/div>\n\u4f7f\u7528\u5982\u4e0b\u7684\u8bed\u6cd5\uff1a<\/p>\n
grep --color \u6b63\u5219\u8868\u8fbe\u5f0f \u6587\u4ef6\u540d\r\n<\/pre>\n\u600e\u4e48\u6837\u4ec5\u4ec5\u53ea\u663e\u793a\u5339\u914d\u51fa\u7684\u5b57\u7b26\uff0c\u800c\u4e0d\u662f\u5339\u914d\u51fa\u7684\u884c\uff1f<\/strong><\/span><\/div>\n\u4f7f\u7528\u5982\u4e0b\u8bed\u6cd5\uff1a<\/p>\n
grep -o \u6b63\u5219\u8868\u8fbe\u5f0f \u6587\u4ef6\u540d\r\n<\/pre>\n\u6b63\u5219\u8868\u8fbe\u5f0f\u9650\u5b9a\u7b26<\/strong><\/div>\n\n\n\n\u9650\u5b9a\u7b26<\/th>\n | \u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n |
\n\n.<\/td>\n | \u5339\u914d\u4efb\u610f\u7684\u4e00\u4e2a\u5b57\u7b26\u3002<\/td>\n<\/tr>\n |
\n?<\/td>\n | \u5339\u914d\u524d\u9762\u7684\u5b50\u8868\u8fbe\u5f0f\uff0c\u6700\u591a\u4e00\u6b21\u3002<\/td>\n<\/tr>\n |
\n*<\/td>\n | \u5339\u914d\u524d\u9762\u7684\u5b50\u8868\u8fbe\u5f0f\u96f6\u6b21\u6216\u591a\u6b21\u3002<\/td>\n<\/tr>\n |
\n+<\/td>\n | \u5339\u914d\u524d\u9762\u7684\u5b50\u8868\u8fbe\u5f0f\u4e00\u6b21\u6216\u591a\u6b21\u3002<\/td>\n<\/tr>\n |
\n{N}<\/td>\n | \u5339\u914d\u524d\u9762\u7684\u5b50\u8868\u8fbe\u5f0f N \u6b21\u3002<\/td>\n<\/tr>\n |
\n{N,}<\/td>\n | \u5339\u914d\u524d\u9762\u7684\u5b50\u8868\u8fbe\u5f0f N \u6b21\u5230\u591a\u6b21\u3002<\/td>\n<\/tr>\n |
\n{N,M}<\/td>\n | \u5339\u914d\u524d\u9762\u7684\u5b50\u8868\u8fbe\u5f0f N \u5230 M \u6b21\uff0c\u81f3\u5c11 N \u6b21\u81f3\u591a M \u6b21\u3002<\/td>\n<\/tr>\n |
\n-<\/td>\n | \u53ea\u8981\u4e0d\u662f\u5728\u5e8f\u5217\u5f00\u59cb\u3001\u7ed3\u5c3e\u6216\u8005\u5e8f\u5217\u7684\u7ed3\u675f\u70b9\u4e0a\uff0c\u8868\u793a\u5e8f\u5217\u8303\u56f4\u3002<\/td>\n<\/tr>\n |
\n^<\/td>\n | \u5339\u914d\u4e00\u884c\u5f00\u59cb\u7684\u7a7a\u5b57\u7b26\u4e32\uff1b\u4e5f\u8868\u793a\u5b57\u7b26\u4e0d\u5728\u8981\u5339\u914d\u7684\u5217\u8868\u4e2d\u3002<\/td>\n<\/tr>\n |
\n$<\/td>\n | \u5339\u914d\u4e00\u884c\u672b\u5c3e\u7684\u7a7a\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n |
\n\\b<\/td>\n | \u5339\u914d\u4e00\u4e2a\u5355\u8bcd\u524d\u540e\u7684\u7a7a\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n |
\n\\B<\/td>\n | \u5339\u914d\u4e00\u4e2a\u5355\u8bcd\u4e2d\u95f4\u7684\u7a7a\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n |
\n\\<<\/td>\n | \u5339\u914d\u5355\u8bcd\u524d\u9762\u7684\u7a7a\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n |
\n\\><\/td>\n | \u5339\u914d\u5355\u8bcd\u540e\u9762\u7684\u7a7a\u5b57\u7b26\u4e32\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n |