shell使用案例之xargs命令

seofangfa shell学习笔记评论1,843阅读模式

案例:采集了一批文章,已经在本地生成好了html文件,现在需要把提取这批文章上线后的完整URL及title部分,用来做一个sitemap方便我提交给百度。

比如http://seofangfa.com/seo-test/seo-test2-baidu-crawltools-improve-index.html,其中有一批文章页,文件名从seo-test1-baidu-crawltools-improve-index.html到seo-testN-baidu-crawltools-improve-index.html,如何实现这个呢?废话不多说,代码如下:

 ls|xargs grep "<title>.*" >sitemap.xml

我解释一下代码的意思。ls就是列出当前目录中所有文件名,然后用xargs挨个把这些文件用grep过滤出<title>部分的内容,然后用重定向命令>输出到文件sitemap.xml中。

文章末尾固定信息

weinxin
我的微信
我的微信
微信扫一扫
 
seofangfa
  • 本文由 seofangfa 发表于 2014年6月24日15:02:09
  • 转载请务必保留本文链接:https://wp.fangfa.me/shell/shell-xargs.html
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证