sed簡單用法

2021-09-21 15:32:21 字數 1323 閱讀 4185

一、替換

1、將替換後的文字顯示在螢幕上

1

sed's/pattern/replace_string/'file

或者通過管道

1

catfile|sed's/pattern/replace_string/'

2、替換原始檔中的文字

1

sed's/pattern/replace_string/g'file

或者1sed-i's/pattern/replace_string/'file

從第n處開始替換匹配的行

1

sed's/pattern/replace_string/ng'file

二、刪除匹配的行1

sed'/pattern/d'

三、用&來標記匹配的字段1

2

3

#sed 's/mail/[&]/' sent |head -20

send [mail]time

mon sep 29 03:16:49 cdt 2014

四、組合表示式1

sed'expression1'|sed'expression2'

或者1sed'expression1;expression2'

五、引用1

2

3

# text=hello

# echo "hello world" |sed "s/$text/hello/"

hello world

sed簡單用法

引數說明 e 以指定的script來處理輸入的文字檔案 f 以指定的script檔案來處理輸入的文字檔案 h 顯示幫助 n 僅顯示script處理後的結果 v 顯示版本資訊 v 反選 動作說明 a 新增,後面跟字串,插入在指定行的下一行 c 取代,後面跟字串,可以取代n1,n2之間的行 d 刪除 i...

mysql的簡單用法 mysql簡單用法

刪除使用者 drop user jack drop比delete刪除的優勢在於drop可以刪除使用者的許可權,更加徹底 更改使用者名稱 rename user jack to jacknew 使用者的都存在與user表中,更改名稱,許可權不變 更改使用者密碼 update mysql.user se...

oracle cursor 簡單用法

procedure changespecialdiscount compid in invarchar2 ccid in invarchar2 cono in invarchar2 is sum cc all number 14 4 0 wsp disc number 14 4 wspcl disc...