当前位置: 移动技术网 > 网络运营>服务器>Linux > shell脚本实现快速生成xml格式sitemap实例分享

shell脚本实现快速生成xml格式sitemap实例分享

2017年12月12日  | 移动技术网网络运营  | 我要评论
用shell快速生成xml格式的sitemap地图文件,中小型网站适用。在本次案例中,生成12053条url的sitemap文件,仅用时4.3秒!shell代码如下: 复

用shell快速生成xml格式的sitemap地图文件,中小型网站适用。在本次案例中,生成12053条url的sitemap文件,仅用时4.3秒!shell代码如下:

复制代码 代码如下:

cat sitemap.txt|awk 'begin{print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<urlset>"}{print "<url>\n<loc>"$0"</loc>\n<lastmod>2014-07-18</lastmod>\n<changefreq>always</changefreq>\n</url>"}end{print "</urlset>"}'

其中sitemap.txt是网站所有url的集合,<lastmod>后面的日期,需要修改为你当时生成sitemap文件时的日期,今天是2014年7月18日,所以我写的是这个。

其实用txt格式的sitemap百度也是认可的,为了体现shell功能强大之处,我才在此非得把txt格式的折腾成xml格式的!!!sitemap.txt内容如下图,总共有12053条url。

最终效果及生成速度,总共12053条url,生成xml格式的sitemap,仅用时4.3秒!速度还是相当快的!

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网