匹配html的嵌入代碼
CODE:
<[^>]*>
匹配[....]的嵌入碼
CODE:
\[[^]]\{1,\}\]
刪除僅由空字符組成的行
CODE:
sed '/^[[:space:]]*$/d' filename
匹配html標(biāo)簽
CODE:
/\(<[^>]*>\)/
例如:從html文件中剔除html標(biāo)簽
CODE:
sed 's/\(<[^>]*>\)//g;/^[[:space:]]*$/d' file.html
例如:要從下列代碼中去除"[]"及其中包括的代碼
CODE:
[b:4c6c2a6554][color=red:4c6c2a6554]一. 替換[/color:4c6c2a6554][/b:4c6c2a6554]
sed 's/\[[^]]\{1,\}\]//g' filename
匹配日期:
CODE:
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]\)
匹配IP地址
CODE:
\([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\}\)
匹配數(shù)字串
CODE:
[-+]*[0-9]\{1,\} 整數(shù)
[-+]*[0-9]\{1,\}\.[0-9]\{1,\} 浮點(diǎn)數(shù)
從字串中解析出兩個(gè)子串(前2各字符和后9個(gè)字符)
CODE:
echo "WeLoveChinaUnix"|sed -e 'H;s/\(..\).*/\1/;x;s/.*\(.\{9\}\)$/\1/;x;G;s/\n/ /'
We ChinaUnix
分解日期串
CODE:
echo 20030922|sed 's/\(....\)\(..\)\(..\)/\1 \2 \3/'|read year month day
echo $year $month $day
文件內(nèi)容倒序輸出
CODE:
sed '1!G;h;$!d' oldfile >newfile
當(dāng)然也可以直接使用tac命令實(shí)現(xiàn)倒序輸出.
posted on 2009-12-07 23:55
chatler 閱讀(172)
評(píng)論(0) 編輯 收藏 引用 所屬分類:
RegularExpression