一:作用
查找行內符合條件的字符串
二:參數
--color=auto
查找test.py中的w字符 grep --color=auto(參數) "w"(查找規則) test.py(查找源文件)
(1)查找包含規則的單詞在文件的第幾行 -n
grep_test.py
import random def number(): return "hello" def string_demo(): return "demo" if __name__ == "__main__": number()
要求:查找 number在grep_test.py文件的第幾行
cat -n grep_test.py 按照行號顯示內容
grep -ni "number" gerp_test.py 忽略大小寫匹配number
(2)過濾開頭結尾 ^ $
要求:查找以if開頭,並顯示行號
grep是以行進行過濾。
(3)取反不以什么什么,-v
要求:不以:結尾的所有行,顯示行號
# TODO