分类: LINUX
2009-11-11 09:38:00
- 錨點(anchor) 用以標識 RE 於句子中的位置所在. 常見有: ^: 表示句首. 如 ^abc 表示以 abc 開首的句子. $: 表示句尾. 如 abc$ 表示以 abc 結尾的句子. \<: 表示詞首. 如 \ - 修飾字符(modifier) 獨立表示時本身不具意義, 專門用以修改前一個 char. set 的出現次數. 常見有: *: 表示前一個 char. set 的出現次數為 0 或多次. 如 ab*c 表示 a 與 c 之間可有 0 或多個 b 存在. ?: 表示前一個 char. set 的出現次數為 0 或 1 次. 如 ab?c 表示 a 與 c 之間可有 0 或 1 個 b 存在. +: 表示前一個 char. set 的出現次數為 1 或多次. 如 ab+c 表示 a 與 c 之間可有 1 或多個 b 存在. {n}: 表示前一個 char. set 的出現次數必須為 n 次. 如 ab{3,}c 表示 a 與 c 之間必須有 3 個 b 存在.{n,}: 表示前一個 char. set 的出現次數至少為 n 次. 如 ab{3,}c 表示 a 與 c 之間至少有 3 個 b 存在. {n,m}: 表示前一個 char. set 的出現次數為 n 到 m 次. 如 ab{3,5}c 表示 a 與 c 之間有 3 到 5 個 b 存在. |
sed [-n] [-e] 'command' file(s) sed [-n] -f scriptfile file(s)
zhyfly@zhyfly:~$ sed 'some-sed-commands' input-file>output-file
[address [,address]]w filename
zhyfly@zhyfly:~/bash$ cat test.txt The honeysuckle band played all night long for only $90. It was an evening of splendid music and company. Too bad the disco floor fell through at 23:00. The local nurse Miss P.Neave was in attendance. zhyfly@zhyfly:~/bash$ sed -e '1,2w test.bak' test.txt The honeysuckle band played all night long for only $90. It was an evening of splendid music and company. Too bad the disco floor fell through at 23:00. The local nurse Miss P.Neave was in attendance. zhyfly@zhyfly:~/bash$ cat test.bak The honeysuckle band played all night long for only $90. It was an evening of splendid music and company.
address r filename
zhyfly@zhyfly:~/bash$ cat test.txt The honeysuckle band played all night long for only $90. It was an evening of splendid music and company. Too bad the disco floor fell through at 23:00. The local nurse Miss P.Neave was in attendance.
zhyfly@zhyfly:~/bash$ sed -e '1p' test.txt The honeysuckle band played all night long for only $90. The honeysuckle band played all night long for only $90. It was an evening of splendid music and company. Too bad the disco floor fell through at 23:00. The local nurse Miss P.Neave was in attendance. zhyfly@zhyfly:~/bash$ sed -n -e '1p' test.txt The honeysuckle band played all night long for only $90.
zhyfly@zhyfly:~/bash$ sed -n -e '2p' test.txt It was an evening of splendid music and company.
zhyfly@zhyfly:~/bash$ sed -n -e '2,3p' test.txt It was an evening of splendid music and company. Too bad the disco floor fell through at 23:00.
zhyfly@zhyfly:~/bash$ sed -n -e '/company/p' test.txt It was an evening of splendid music and company.
zhyfly@zhyfly:~/bash$ sed -n -e '2,/23:00/p' test.txt It was an evening of splendid music and company. Too bad the disco floor fell through at 23:00.
zhyfly@zhyfly:~/bash$ sed -n -e '2,3!p' test.txt The honeysuckle band played all night long for only $90. The local nurse Miss P.Neave was in attendance.