Linux三劍客老三 grep

2021-09-24 07:47:46 字數 1432 閱讀 5597

「 linux三劍客,最常用的linux命令之grep——程式設計三分鐘」

grep擅長查詢功能

在這裡為了節省篇幅,我就不一一解釋了,只介紹一些非常常用的組合。

$ grep -rl love *

dir/file3.txt

file.txt

file2.txt

複製**

$ grep -inr "it doesn』t" *

dir/file3.txt:38:it doesn』t matter where

file.txt:38:it doesn』t matter where

file2.txt:38:it doesn』t matter where

複製**

一般用於定位日誌問題,-a 2 -b 2 也可以替換成-c 2

$ grep -in "it doesn』t" file.txt -a 2 -b 2

file.txt-36-the way that ypu change my world

file.txt-37-when i』m with you

file.txt:38:it doesn』t matter where we're from and where

file.txt-39-as long as your with me all the way

file.txt-40-and the nights are long and lonely and

複製**

$ ps -ef | grep -i wei

501 1807 1 0 25 519 ?? 5:29.55 /usr/bin/weiyun -psn_0_176171

501 92256 1851 0 10:32 grep --color=auto

$ ps -ef | grep -i wei | grep -v grep

501 1807 1 0 25 519 ?? 5:29.55 /usr/bin/weiyun -psn_0_176171

複製**

$ grep -e "love|change" file.txt

i love you

i love you

the way that you change my world

love may come and love may go複製**

echo [email protected] | grep -p "^[a-za-z0-9\u4e00-\u9fa5]\+\@[a-za-z0-9_-]\+\(\.[a-za-z0-9_-]\+\)"

[email protected]複製**

linux 三劍客老三grep

linux中常用的文字 awk,sed,grep 處理工具之一 首先談一下grep命令的常用格式為 grep 選項 模式 檔案 grep家族總共有三個 grep,egrep,fgrep 引數 引數 用途 color auto 過濾的內容加顏色 v取反 r遞迴查詢 i不區分大小寫 n顯示行號 w按單詞...

1三劍客老三grep

三劍客的價值 gerp取一行,用於資料查詢定位 awk取行中的某欄位,用於資料切片 sed常用於資料修改,類似於資料更新 用sql語句表示三劍客的用途 grep select from table從 table 表中選擇所有資料 awk select field from table從表中選擇字段 ...

linux 三劍客之 grep

grep 是 linux系統中最重要的命令之一 其功能是從文字或者管道資料中篩選匹配的行及資料 如果配置正規表示式技術一起使用,則其功能更強大,它是linux運維人員必須要掌握的命令之一 usage grep option pattern file 用法 grep 引數 要搜尋的內容 檔案 eg r...