求高人帮忙:shell能否实现这样的需求?
时间:2011-03-09
来源:互联网
文件的每行都是类似这样的
/web/news/2011/0309/1.shtml
/web/news/2011/0309/2.shtml
/web/news/2011/0308/3.shtml
/news110309-1.shtml
/news110309-2.shtml
/news110308-3.shtml
能否实现把文件格式是
/web/news/2011/0309/1.shtml
转成
/news110309-1.shtml
就是去掉前面的/web/,然后格式是news+年(2010年只取10,2009年只取09)+月+日+‘-’+id
万分感谢先!唉,头大中
/web/news/2011/0309/1.shtml
/web/news/2011/0309/2.shtml
/web/news/2011/0308/3.shtml
/news110309-1.shtml
/news110309-2.shtml
/news110308-3.shtml
能否实现把文件格式是
/web/news/2011/0309/1.shtml
转成
/news110309-1.shtml
就是去掉前面的/web/,然后格式是news+年(2010年只取10,2009年只取09)+月+日+‘-’+id
万分感谢先!唉,头大中
作者: kookies 发布时间: 2011-03-09
echo "/web/news/2011/0309/1.shtml" |gawk '{print gensub(/\/web(\/.*)\/20(..)\/(.*)\/(.*)/,"\\1\\2\\3-\\4",1,$0)}'
/news110309-1.shtml
/news110309-1.shtml
作者: yinyuemi 发布时间: 2011-03-09
本帖最后由 昭襄王 于 2011-03-09 14:35 编辑
复制代码
- sed -e 's:/:-:5' -e 's:news/..:news:' -e 's:/web::g' -e 's:/::g' file
- news110309-1.shtml
- news110309-2.shtml
- news110308-3.shtml
作者: 昭襄王 发布时间: 2011-03-09
QUOTE:
昭襄王 发表于 2011-03-09 14:32
谢谢!缺少最前面的/
结果需要是
/news110309-1.shtml
作者: kookies 发布时间: 2011-03-09
回复 kookies
复制代码
- sed -e 's:/:-:5' -e 's:news/..:news:' -e 's:/web::g' -e 's:/::2' t002
- /news110309-1.shtml
- /news110309-2.shtml
- /news110308-3.shtml
作者: 昭襄王 发布时间: 2011-03-09
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28