![]() |
![]() |
![]() |
![]() |
![]() |
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 |