匹配html的嵌入代码 <[^>]*>
匹配[....]的嵌入码 \[[^]]\{1,\}\]
删除仅由空字符组成的行 sed '/^[[:space:]]*$/d' filename
匹配html标签 /\(<[^>]*>\)/ 例如:从html文件中剔除html标签 sed 's/\(<[^>]*>\)//g;/^[[:space:]]*$/d' file.html
例如:要从下列代码中去除"[]"及其中包括的代码 [b:4c6c2a6554][color=red:4c6c2a6554]一. 替换[/color:4c6c2a6554][/b:4c6c2a6554] sed 's/\[[^]]\{1,\}\]//g' filename
匹配日期: 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地址 \([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\}\)
匹配数字串 [-+]*[0-9]\{1,\} 整数 [-+]*[0-9]\{1,\}\.[0-9]\{1,\} 浮点数
从字串中解析出两个子串(前2各字符和后9个字符) echo "WeLoveChinaUnix"|sed -e 'H;s/\(..\).*/\1/;x;s/.*\(.\{9\}\)$/\1/;x;G;s/\n/ /' We ChinaUnix
分解日期串 echo 20030922|sed 's/\(....\)\(..\)\(..\)/\1 \2 \3/'|read year month day echo $year $month $day
文件内容倒序输出 sed '1!G;h;$!d' oldfile >newfile |