aix基本命令之grep

wmlm發表於2007-03-07
在檔案內部查詢文字字串(grep 命令)[@more@]

使用 grep 命令搜尋指定的檔案,以查詢由 Pattern 引數指定的模式,並將每個匹配的行寫至標準輸出。
以下是如何使用 grep 命令的示例:
" 要在名為 pgm.s 的檔案裡搜尋包含模式匹配字元 *、^、?、[、]、(、)、{ 和 } 其中幾個的模式(這種情況下以任意大小寫字母開頭的行),請輸入以下命令:
grep "^[a-zA-Z]" pgm.s
該命令顯示 pgm.s 檔案中所有以字母開頭的行。
" 要顯示名為 sort.c 的檔案中所有不匹配某特定模式的行,請輸入以下命令:
grep -v bubble sort.c
該命令顯示 sort.c 檔案中不包含單詞 bubble 的所有行。
" 要顯示 ls 命令的輸出中匹配字串 staff 的行,請輸入以下命令:
ls -l | grep staff

4 To search for a $ (dollar sign) in the file named test2, enter:
grep test2

5 To search recursively through /tmp to find files which have the
word IBM without recursing through links pointing to directories,
type:

grep -R IBM /tmp
OR
grep -r -H IBM /tmp

6 To search recursively through /tmp to find files which have the
word IBM and recurse through links as well, type:

grep -r IBM /tmp
OR
grep -R -L IBM /tmp

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/271063/viewspace-903242/,如需轉載,請註明出處,否則將追究法律責任。

相關文章