第十二章 正規表示式

2021-05-22 13:09:17 字數 3903 閱讀 7987

第十二章 正規表示式

grep [-acinv] '搜尋字串' filename

grep -n 『the』 regular_express.txt

grep -vn 『the』 regular_express.txt

grep -in 『the』 regular_express.txt

grep -n 't[ae]st' regular_express.txt

grep -n 'oo' regular_express.txt

grep -n '[^g]oo' regular_express.txt

grep -n '[^a-z]oo' regular_express.txt

grep -n '[0-9]' regular_express.txt

grep -n '^[a-za-z]' regular_express.txt

grep -n '/.$' regular_express.txt

grep -n '^$' regular_express.txt

grep -v '^$' /etc/syslog.conf | grep -v '^$'

grep -n 'g..d' regular_express.txt

grep -n 'ooo*' regular_express.txt

grep -n 'goo*g' regular_express.txt

grep -n 'g*g' regular_express.txt

grep -n 'g.*g' regular_express.txt

grep -n '[0-9][0-9]*' regular_express.txt

grep -n 'o/' regular_express.txt

grep -n 'go/g' regular_express.txt

grep -n 'go/g' regular_express.txt

egrep支援擴充套件正規表示式

+ ? | ()

. 任意乙個字元

* 重複字元

{} 限定連續重複字元範圍

字元集合的重複特殊字元

格式化顯示:printf

sed 工具 整行比較

sed [-nefr]

nl /etc/passwd | sed '2, 5d'

nl /etc/passwd | sed '2a drink tea'

nl /etc/passwd | sed '2a drink tea or ...... > drink beer ?'

nl /etc/passwd | sed '2,5c no 2-5 number'

nl /etc/passwd | sed -n '5,7p'

ifconfig eth0 | grep 'inet' | sed 's/^.*addr://g' | sed

's/bcast.*$//g'

cat /etc/man.config | grep 'man' | sed 's/#.*//g' | >

sed '/^$/d'

awk 用於一行中分成數個「字段」來處理

awk 條件1 條件2 ... filename

last | awk ''

last | awk ''

cat /etc/passwd | awk 'begin $3 < 10 '

diff 檔案比較

cmp 比較二進位制

patch

習題:1.要查詢某個檔案,其中含有boot字串,這個檔案在/etc下,如何找出

這個檔案

答:ls /etc | grep 'boot'

2.在/etc下,只要含有xyz3個字元的任何乙個字元的那一行,就顯示出來,

怎樣進行

答:ls /etc [xyz]

3.怎樣找出在/etc下檔案內容含有(*)的檔名

答:ls /etc | grep '/*'

grep [-acinv] '搜尋字串' filename

grep -n 『the』 regular_express.txt

grep -vn 『the』 regular_express.txt

grep -in 『the』 regular_express.txt

grep -n 't[ae]st' regular_express.txt

grep -n 'oo' regular_express.txt

grep -n '[^g]oo' regular_express.txt

grep -n '[^a-z]oo' regular_express.txt

grep -n '[0-9]' regular_express.txt

grep -n '^[a-za-z]' regular_express.txt

grep -n '/.$' regular_express.txt

grep -n '^$' regular_express.txt

grep -v '^$' /etc/syslog.conf | grep -v '^$'

grep -n 'g..d' regular_express.txt

grep -n 'ooo*' regular_express.txt

grep -n 'goo*g' regular_express.txt

grep -n 'g*g' regular_express.txt

grep -n 'g.*g' regular_express.txt

grep -n '[0-9][0-9]*' regular_express.txt

grep -n 'o/' regular_express.txt

grep -n 'go/g' regular_express.txt

grep -n 'go/g' regular_express.txt

egrep支援擴充套件正規表示式

+ ? | ()

. 任意乙個字元

* 重複字元

{} 限定連續重複字元範圍

字元集合的重複特殊字元

格式化顯示:printf

sed 工具 整行比較

sed [-nefr]

nl /etc/passwd | sed '2, 5d'

nl /etc/passwd | sed '2a drink tea'

nl /etc/passwd | sed '2a drink tea or ...... > drink beer ?'

nl /etc/passwd | sed '2,5c no 2-5 number'

nl /etc/passwd | sed -n '5,7p'

ifconfig eth0 | grep 'inet' | sed 's/^.*addr://g' | sed

's/bcast.*$//g'

cat /etc/man.config | grep 'man' | sed 's/#.*//g' | >

sed '/^$/d'

awk 用於一行中分成數個「字段」來處理

awk 條件1 條件2 ... filename

last | awk ''

last | awk ''

cat /etc/passwd | awk 'begin $3 < 10 '

diff 檔案比較

cmp 比較二進位制

patch

習題:1.要查詢某個檔案,其中含有boot字串,這個檔案在/etc下,如何找出

這個檔案

答:ls /etc | grep 'boot'

2.在/etc下,只要含有xyz3個字元的任何乙個字元的那一行,就顯示出來,

怎樣進行

答:ls /etc [xyz]

3.怎樣找出在/etc下檔案內容含有(*)的檔名

答:ls /etc | grep '/*'

JS 第十二課 正規表示式

直接量建立 pattern attrs物件建立 new regexp pattern,attrs 引數 直接量字元 123abc 代表字母或數字本身符號 含義 o null t製表符 v垂直製表符 n換行符 r回車符 f換頁符 字元類 符號含義 在括號中的任意乙個字元 不在括號中的任意乙個字元 除換...

第十二章 檔案

文字檔案 文字檔案是一種由若干字元構成的檔案,可以用文字編輯器進行閱讀或編輯。以txt py html等為字尾的檔案都是文字檔案。2.二進位制檔案 二進位制檔案一般是指不能用文字編輯器閱讀或編輯的檔案。以 mp4 png等為字尾的檔案都是二進位制檔案,如果想要開啟或修改這些檔案,必須通過特定軟體進行...

第十二章 dp

動態規劃策略 將原始問題拆分為多個子問題,將子問題結果記錄,方便復用子問題的解 遞迴 記憶化 遞推 是動態規劃的一體兩面,本質都是一樣的 遞推減少了呼叫次數,空間上還能優化,一般選擇遞推方式 遞迴 記憶化 int memo maxn 將o 2 n o n intfibonacci int n 遞推 ...