免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2198 | 回复: 5
打印 上一主题 下一主题

怎么提取这个文本信息? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-03-26 02:38 |只看该作者 |倒序浏览
<span id="thread_17873"><a href="thread-17873-1-2.html">每日学口语(1.31):The finest edge is made with the blunt whetstone</a></span>

需要得到的结果是:
thread-17878-1-2.html#The finest edge is made with the blunt whestone

自己写了个,但是很麻烦,用了很多管道,不知道有没有简单点的方法,主要是这行字符串没什么规律。

论坛徽章:
0
2 [报告]
发表于 2008-03-26 03:07 |只看该作者
[root@localhost ~]# cat file
<span id="thread_17873"><a href="thread-17873-1-2.html">每日学口语(1.31):The finest edge is made with the blunt whetstone</a></span>
[root@localhost ~]# cat file |awk -F'[":<]' '{print $6"#"$8}'
thread-17873-1-2.html#The finest edge is made with the blunt whetstone

论坛徽章:
0
3 [报告]
发表于 2008-03-26 10:59 |只看该作者
原帖由 meeslo 于 2008-3-26 03:07 发表
[root@localhost ~]# cat file
每日学口语(1.31):The finest edge is made with the blunt whetstone
[root@localhost ~]# cat file |awk -F'[":

谢谢,脑筋转不过来,没想到要设定多个分隔符。

论坛徽章:
0
4 [报告]
发表于 2008-03-26 15:27 |只看该作者
原帖由 meeslo 于 2008-3-26 03:07 发表
[root@localhost ~]# cat file
每日学口语(1.31):The finest edge is made with the blunt whetstone
[root@localhost ~]# cat file |awk -F'[":


这个比较经典,嘿嘿

论坛徽章:
0
5 [报告]
发表于 2008-03-26 16:33 |只看该作者

  1. sed -r 's/<span[^>]*><a href="([^"]*)">[^:]*:([^<]*)<\/a><\/span>/\1#\2/'
复制代码


分析,好象结构是一个span,内部是一个a,a的内容是用:分隔成前后了,需要取出的是a的href和a的内容的:符号后面的内容。

论坛徽章:
0
6 [报告]
发表于 2008-03-26 16:36 |只看该作者
原帖由 springwind426 于 2008-3-26 16:33 发表

sed -r 's/]*>

比较专业
处理html 有时候比较头痛
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP