Grep 從檔案中搜尋字串

2021-06-20 14:16:25 字數 692 閱讀 9295

-o       只輸出匹配部分(把匹配部分從行中挑出來)

-h 顯示檔名

-h 不顯示檔名

-c n 顯示匹配上下文

-v 反檢索,顯示不匹配的行

-l 輸出匹配的檔案

-l 輸出不匹配的檔案

-n 顯示行號

-i       忽略大小寫

-w 匹配整個word

-x 匹配整行

-p       perl正則風格

-e 擴充套件的(extension)正規表示式。grep -e等同egrep。

-f 固定的(fixed)字串搜尋。grep -f等同fgrep。

-i       不搜尋二進位制檔案,等同--binary-files=without-match

-a 把二進位制檔案當做文字檔案,等同--binary-files=text

-c       統計匹配行數

-s slient模式,不顯示不存在或者無法讀取檔案的錯誤資訊

linux 檔案中搜尋字串命令 grep

用 grep 搜尋文字檔案 如果您要在幾個文字檔案中查詢一字串,可以使用 grep 命令。grep 在文字中搜尋指定的字串。假設您正在 usr src linux documentation 目錄下搜尋帶字串 magic 的檔案 grep magic usr src linux documentat...

使用grep搜尋多個單詞或字串

語法 一些別的實現方法 grep word1 word2 word3 path to file search all text files grep word txt search all python files for worda or wordb grep worda wordb py gre...

Centos之字串搜尋命令grep

grep 選項 字串 檔名 在檔案當中匹配符合條件的字串 選項 i 忽略大小寫 v 排除指定字串 root localhost grep work anaconda ks.cfg network information network bootproto dhcp device ens33 onbo...