home products tech support contact us

 Linux 技術支援    ⇒   基礎篇    進階篇    補腦篇    指令索引    中⇒ENG
版權所有, 引用請註明出處
 

grep 檔案中尋找字串

grep 指令是Unix-like 中的一個強大工具,用於在文字檔案中搜尋和匹配。grep 名稱來自〝Global Regular Expression Print〞, grep 有很強的文件搜尋能力,且有支援正規表示法

其基本語法為 grep [OPTIONS] PATTERN [FILE...] .其中〝PATTERN 〞為要搜索的模本或式或正規表示法。

常用的選項有:

例:
$ man tar | grep -n 'GNU' ←搜尋文件中有〝GNU〞字串並輸出其行號
12:     GNU `tar' saves many files together into a single tape or disk archive
88:     handle new GNU-format incremental backup
$$ seq 1 10000 | grep '789' ← 搜尋有〝789〞的文字
789
1789
2789

更多 grep 範例和說明和選項參考連結