
英:/'ɡrep/
n. UNIX工具程式;可做文件内的字符串查找
n. (Grep)人名;(蘇裡)格雷普
Lots of people use grep.
許多人都使用grep。
Show only the matches with grep.
使用grep僅顯示匹配項。
Auditing You can do grep on querylog.
審計可以對querylog執行grep。
List the files and grep for the inode.
列出文件并使用grep搜索inode。
To correct that, I added an extra grep call.
為了糾正那一點,我添加了一個額外的grep調用。
grep 是 Unix 和類 Unix 系統(如 Linux)中廣泛使用的命令行工具,全稱為Global Regular Expression Print。它主要用于在文本文件中搜索與指定模式(如字符串或正則表達式)匹配的行,并将結果輸出到終端或文件。其核心功能是通過正則表達式實現高效的模式匹配,是數據處理、日志分析和編程開發中的基礎工具之一。
模式匹配
grep 通過用戶定義的正則表達式或固定字符串,逐行掃描文件内容。當某一行包含匹配項時,grep 會輸出該行。例如,命令 grep "error" log.txt
會顯示 log.txt
中所有包含“error”的行。
正則表達式支持
grep 支持基礎正則表達式(BRE)和擴展正則表達式(ERE),允許複雜模式匹配,如 grep -E "^[A-Za-z]+" file.txt
可匹配以字母開頭的行。高級功能包括字符類([0-9]
)、重複符(*
、+
)和錨點(^
、$
)等。
常用選項
-i
:忽略大小寫(如 grep -i "warning" file
)-r
:遞歸搜索目錄(如 grep -r "function" /src/
)-n
:顯示匹配行的行號(如 grep -n "bug" code.py
)-v
:反向選擇(輸出不匹配的行)-c
:統計匹配行數。典型應用
grep "404" access.log
)。grep -r "calculate_score" .
)。grep "023-" sales.csv
)。“grep”是一個常用的命令行工具,主要用于在文本中搜索匹配特定模式(如字符串或正則表達式)的内容。以下是詳細解釋:
g/re/p
(Global Regular Expression Print),意為“全局正則表達式打印”。grep [選項] '搜索模式' 文件名
grep 'error' log.txt
→ 在log.txt
中查找包含“error”的行。-i
:忽略大小寫(如 grep -i 'warning' file
)。-v
:反向匹配,輸出不包含模式的行。-n
:顯示匹配行的行號。-r
或 -R
:遞歸搜索目錄中的文件。-E
:支持擴展正則表達式(等同于 egrep
)。grep '404' access.log
)。grep -r 'function_name' src/
)。cat file.txt | grep 'pattern'
)。egrep
:支持更複雜的正則表達式(現可用 grep -E
替代)。fgrep
:僅匹配固定字符串(現可用 grep -F
替代)。若需深入學習,可通過 man grep
查看完整手冊,或參考線上Linux命令文檔。
by planeStewart Islandcounselormink coatrostrumgladdestinquiringJerroldjuxtaposingLeahauthorised representativeblocks of flatsgypsum boardon the jarout of dangertandem rollingupdate nowvibration damperacademicismaerothermotherapyamniosisbaneberryCainozoicchaffychymopapainEssexFETisodynammerergasiazymogram