- 論壇徽章:
- 1
|
匹配html的嵌入代碼
匹配[....]的嵌入碼
刪除僅由空字符組成的行
- sed '/^[[:space:]]*$/d' filename
復(fù)制代碼
匹配html標(biāo)簽
例如:從html文件中剔除html標(biāo)簽
- sed 's/\(<[^>]*>\)//g;/^[[:space:]]*$/d' file.html
復(fù)制代碼
例如:要從下列代碼中去除"[]"及其中包括的代碼
- [b:4c6c2a6554][color=red:4c6c2a6554]一. 替換[/color:4c6c2a6554][/b:4c6c2a6554]
- sed 's/\[[^]]\{1,\}\]//g' filename
復(fù)制代碼
匹配日期:
- Month, Day, Year [A-Z][a-z]\{3,9\}, [0-9]\{1,2\}, [0-9]\{4\}
- 2003-01-28 或 2003.10.18 或 2003/10/10 或 2003 10 10
- \([0-9]\{4\}[ /-.][0-2][0-9][ /-.][0-3][0-9]\)
復(fù)制代碼
匹配IP地址
- \([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)
- \(\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\)
復(fù)制代碼
匹配數(shù)字串
- [-+]*[0-9]\{1,\} 整數(shù)
- [-+]*[0-9]\{1,\}\.[0-9]\{1,\} 浮點(diǎn)數(shù)
復(fù)制代碼
從字串中解析出兩個(gè)子串(前2各字符和后9個(gè)字符)
- echo "WeLoveChinaUnix"|sed -e 'H;s/\(..\).*/\1/;x;s/.*\(.\{9\}\)$/\1/;x;G;s/\n/ /'
- We ChinaUnix
復(fù)制代碼
分解日期串
- echo 20030922|sed 's/\(....\)\(..\)\(..\)/\1 \2 \3/'|read year month day
- echo $year $month $day
復(fù)制代碼
文件內(nèi)容倒序輸出
- sed '1!G;h;$!d' oldfile >newfile
復(fù)制代碼 |
|