涓?銆€grep瀹舵棌:
聽聽 聽
聽聽 1.聽 grep閫€鍑虹姸鎬侊細
聽聽 聽0: 琛ㄧず鎴愬姛锛?/span>
聽聽 聽1: 琛ㄧず鍦ㄦ墍鎻愪緵鐨勬枃浠舵棤娉曟壘鍒板尮閰嶇殑pattern锛?/span>
聽聽 聽2: 琛ㄧず鍙傛暟涓彁渚涚殑鏂囦欢涓嶅瓨鍦ㄣ€?/span>
聽聽 聽瑙佸涓嬬ず渚嬶細
聽聽 聽/> grep 'root' /etc/passwd
聽聽 聽root:x:0:0:root:/root:/bin/bash
聽聽 聽operator:x:11:0:operator:/root:/sbin/nologin
聽聽 聽/> echo $?
聽聽 聽0
聽聽 聽
聽聽 聽/> grep 'root1' /etc/passwd聽 #鐢ㄦ埛root1骞朵笉瀛樺湪
聽聽 聽/> echo $?
聽聽 聽1
聽聽 聽
聽聽 聽/> grep 'root' /etc/passwd1聽 #杩欓噷鐨?etc/passwd1鏂囦欢骞朵笉瀛樺湪
聽聽 聽grep: /etc/passwd1: No such file or directory
聽聽 聽/> echo $?
聽聽 聽2
聽聽 聽
聽聽 2.聽 grep涓簲鐢ㄦ鍒欒〃杈惧紡鐨勫疄渚嬶細
聽聽 聽闇€瑕佽鏄庣殑鏄笅闈㈡墍娑夊強鐨勬鍒欒〃杈惧紡鍦ㄤ笂涓€绡囦腑宸茬粡缁欏嚭浜嗚缁嗙殑璇存槑锛屽洜姝ゅ湪鐪嬩笅闈緥瀛愮殑鏃跺€欙紝鍙互涓庡墠涓€绡囩殑姝e垯璇存槑閮ㄥ垎缁撳悎鐫€鐪嬨€?br>聽聽 聽/> cat testfile
聽聽聽 northwest聽聽聽聽聽聽聽 NW聽聽聽聽聽 Charles Main聽聽聽聽聽聽聽聽聽聽 3.0聽聽聽聽 .98聽聽聽聽 3聽聽聽聽聽聽 34
聽聽 聽western聽聽聽聽聽聽聽聽聽聽 WE聽聽聽聽聽聽 Sharon Gray聽聽聽聽聽聽聽聽聽 5.3聽聽聽聽 .97聽聽聽聽 5聽聽聽聽聽聽 23
聽聽 聽southwest聽聽聽聽聽聽 SW聽聽聽聽聽聽 Lewis Dalsass聽聽聽聽聽聽聽聽 2.7聽聽聽聽 .8聽聽聽聽聽聽 2聽聽聽聽聽聽 18
聽聽 聽southern聽聽聽聽聽聽聽聽 SO聽聽聽聽聽聽 Suan Chin聽聽聽聽聽聽聽聽聽聽聽聽聽聽 5.1聽聽聽聽 .95聽聽聽聽 4聽聽聽聽聽聽 15
聽聽 聽southeast聽聽聽聽聽聽 SE聽聽聽聽聽聽聽 Patricia Hemenway聽聽聽 4.0聽聽聽聽 .7聽聽聽聽聽聽 4聽聽聽聽聽聽 17
聽聽 聽eastern聽聽聽聽聽聽聽聽聽聽 EA聽聽聽聽聽聽聽 TB Savage聽聽聽聽聽聽聽聽聽聽聽 聽 4.4聽聽聽聽 .84聽聽聽聽 5聽聽聽聽聽聽 20
聽聽 聽northeast聽聽聽聽聽聽聽 NE聽聽聽聽聽聽聽 AM Main Jr.聽聽聽聽聽聽聽聽聽聽聽聽聽 5.1聽聽聽聽 .94聽聽聽聽 3聽聽聽聽聽聽 13
聽聽 聽north聽聽聽聽聽聽聽聽聽聽聽聽聽 NO聽聽聽聽聽聽 Margot Weber聽聽聽聽聽聽聽聽聽 4.5聽聽聽聽 .89聽聽聽聽 5聽聽聽聽聽聽 9
聽聽 聽central聽聽聽聽聽聽聽 聽 聽 CT聽聽聽聽聽聽聽 Ann Stephens聽聽聽聽聽聽聽聽聽 5.7聽聽聽聽 .94聽聽聽聽 5聽聽聽聽聽聽 13
聽聽聽
聽聽 聽/> grep NW testfile聽聽聽聽 #鎵撳嵃鍑簍estfile涓墍鏈夊寘鍚玁W鐨勮銆?br>聽聽 聽northwest聽聽聽聽聽聽 NW聽聽聽聽聽 Charles Main聽聽 聽聽聽 聽3.0聽聽聽聽 .98聽聽聽聽 3聽聽聽聽聽聽 34
聽聽 聽
聽聽 聽/> grep '^n' testfile聽聽 #鎵撳嵃鍑轰互n寮€澶寸殑琛屻€?br>聽聽 聽northwest聽聽聽聽聽聽 NW聽聽聽聽聽 Charles Main聽聽 聽聽聽 聽3.0聽聽聽聽 .98聽聽聽聽 3聽聽聽聽聽聽 34
聽聽 聽northeast聽聽聽聽聽聽聽 NE聽聽聽聽聽聽 AM Main Jr.聽聽聽 聽聽聽 聽 5.1聽聽聽聽 .94聽聽聽聽 3聽聽聽聽聽聽 13
聽聽 聽north聽聽聽聽聽聽聽聽聽聽聽聽聽 NO聽聽聽聽聽 Margot Weber聽聽 聽聽 4.5聽聽聽聽 .89聽聽聽聽 5聽聽聽聽聽聽 9
聽聽 聽
聽聽 聽/> grep '4$' testfile聽聽 #鎵撳嵃鍑轰互4缁撳熬鐨勮銆?br>聽聽 聽northwest聽聽聽聽聽聽 NW聽聽聽聽聽 Charles Main聽聽 聽聽聽 聽3.0聽聽聽聽 .98聽聽聽聽 3聽聽聽聽聽聽 34
聽聽 聽
聽聽 聽/> grep '5\..' testfile #鎵撳嵃鍑虹涓€涓瓧绗︽槸5锛屽悗闈㈣窡鐫€涓€涓?瀛楃锛屽湪鍚庨潰鏄换鎰忓瓧绗︾殑琛屻€?br>聽聽 聽western聽聽聽聽聽聽聽聽 WE聽聽聽聽聽 Sharon Gray聽聽聽 聽聽聽 聽5.3聽聽聽聽 .97聽聽聽聽 5聽聽聽聽聽聽 23
聽聽 聽southern聽聽聽聽聽聽聽 SO聽聽聽聽聽 Suan Chin聽聽聽聽聽 聽聽聽 聽聽 5.1聽聽聽聽 .95聽聽聽聽 4聽聽聽聽聽聽 15
聽聽 聽northeast聽聽聽聽聽聽 NE聽聽聽聽聽 AM Main Jr.聽聽聽 聽聽聽 聽聽聽 5.1聽聽聽聽 .94聽聽聽聽 3聽聽聽聽聽聽 13
聽聽 聽central聽聽聽聽聽聽聽聽聽聽 CT聽聽聽聽聽 Ann Stephens聽聽 聽聽聽 聽5.7聽聽聽聽 .94聽聽聽聽 5聽聽聽聽聽聽 13
聽聽 聽
聽聽 聽/> grep '\.5' testfile聽 #鎵撳嵃鍑烘墍鏈夊寘鍚?5鐨勮銆?br>聽聽 聽north聽聽聽聽聽聽聽聽聽聽 NO聽聽聽聽聽 Margot Weber聽聽 聽聽聽 聽4.5聽聽聽聽 .89聽聽聽聽 5聽聽聽聽聽聽 9
聽聽 聽/> grep '^[we]' testfile #鎵撳嵃鍑烘墍鏈変互w鎴杄寮€澶寸殑琛屻€?br>聽聽 聽western聽聽聽聽聽聽聽聽 WE聽聽聽聽聽 Sharon Gray聽聽聽 聽聽聽 聽5.3聽聽聽聽 .97聽聽聽聽 5聽聽聽聽聽聽 23
聽聽 聽eastern聽聽聽聽聽聽聽聽聽 EA聽聽聽聽聽 TB Savage聽聽聽聽聽 聽聽聽 聽 4.4聽聽聽聽 .84聽聽聽聽 5聽聽聽聽聽聽 20
聽聽 聽
聽聽 聽<