10 Sed正規表示式

2021-08-14 16:50:31 字數 745 閱讀 4914

[-] 區間

\? -e 的時候不需要\

\+ -e 的時候不需要 \

或者 \ 轉義字元

\r\n

posix 型別的的正則

[:alnum:]

[:alpha:]

[:blank:]

[:digit:]

[:lower:]

… 我覺得用不到 我反正我是不怎麼用

元字元含義

\bword 邊界

\b非word 邊界

\sspace

\s非space

\wword

\w非word

\`完全匹配

關於 加強版正規表示式 有的unix 或者 linux 版本可能有差異 推薦使用 -e 選項 ubuntu 還可以使用 -r 選型 是一樣的的功能

ubuntu 文件裡面沒有 -e 選項 但是仍可以使用

dingmac@ubuntu:~$ seq 105 | sed -en '/[0-9]/p' 

100101

102103

104105

dingmac@ubuntu:~$ seq 105 | sed -rn '/[0-9]/p'

100101

102103

104105

dingmac@ubuntu:~$ seq 105 | sed -n '/[0-9]/p'

nothing...

sed 正規表示式

如果testfile的內容是 welcome to the world of regexp 現在要去掉所有的html標籤,使輸出結果為 hello world welcome to the world of regexp 怎麼做呢?如果用下面的命令 sed s g testfile 結果是兩個空行,...

sed 常用正規表示式

1.乙個比較實用的正規表示式 匹配html的嵌入 匹配 的嵌入碼 刪除僅由空字元組成的行 sed space d filename 匹配html標籤 例如 從html檔案中剔除html標籤 sed s g space d file.html 例如 要從下列 中去除 及其中包括的 b 4c6c2a65...

Linux正規表示式 sed

相比於grep,sed可以替換內容並輸出到螢幕上。sed 選項 動作 filename選項 n 將經過sed命令處理過的行輸出到螢幕 e 允許對輸入資料應用多條sed命令 i 用sed的修改結果直接修改所讀取的檔案 動作 d 刪除 p 列印 s 字串替換 本行 g 本行全域性替換 列印 etc pa...