posts - 297,  comments - 15,  trackbacks - 0

匹配html的嵌入代码

CODE:
<[^>]*>

匹配[....]的嵌入码

CODE:
\[[^]]\{1,\}\]

删除仅由空字符组成的行

CODE:
sed '/^[[:space:]]*$/d' filename

匹配html标签

CODE:
/\(<[^>]*>\)/

例如:从html文件中剔除html标签

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\}\)

匹配数字串

CODE:
[-+]*[0-9]\{1,\} 整数
[-+]*[0-9]\{1,\}\.[0-9]\{1,\}  浮点数

从字串中解析出两个子串(前2各字符和后9个字符)

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

文件内容倒序输出

CODE:
sed '1!G;h;$!d'  oldfile >newfile
当然也可以直接使用tac命令实现倒序输出.

posted on 2009-12-07 23:55 chatler 阅读(157) 评论(0)  编辑 收藏 引用 所属分类: RegularExpression

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2009年12月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用链接

留言簿(10)

随笔分类(307)

随笔档案(297)

algorithm

Books_Free_Online

C++

database

Linux

Linux shell

linux socket

misce

  • cloudward
  • 感觉这个博客还是不错,虽然做的东西和我不大相关,觉得看看还是有好处的

network

OSS

  • Google Android
  • Android is a software stack for mobile devices that includes an operating system, middleware and key applications. This early look at the Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.
  • os161 file list

overall

搜索

  •  

最新评论

阅读排行榜

评论排行榜