免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: bblxl2012
打印 上一主题 下一主题

[文本处理] 怎么去掉重复的时间 [复制链接]

论坛徽章:
2
射手座
日期:2014-10-10 15:59:4715-16赛季CBA联赛之上海
日期:2016-03-03 10:27:14
11 [报告]
发表于 2013-07-12 10:51 |只看该作者
回复 8# bblxl2012
  1. sed -rn 'h;:a;n;/^\|/H;/^[^|]/{x;bb};${x;bb};ba;:b;s/([^|]+\|([^|]+)\|[^\n]+)(.*)\n\|\2(\|.*)/\1\3\n|\4/;tb;p;ba'
复制代码

论坛徽章:
2
亥猪
日期:2013-12-24 16:24:04狮子座
日期:2014-01-03 14:56:30
12 [报告]
发表于 2013-07-12 11:47 |只看该作者
本帖最后由 bblxl2012 于 2013-07-12 13:30 编辑
yinyuemi 发表于 2013-07-12 10:51
回复 8# bblxl2012


谢谢。辛苦了。能解释一下吗?

论坛徽章:
2
射手座
日期:2014-10-10 15:59:4715-16赛季CBA联赛之上海
日期:2016-03-03 10:27:14
13 [报告]
发表于 2013-07-12 16:27 |只看该作者
回复 12# bblxl2012
  1. sed -rn '
  2. h;  # store 1st line to hold space
  3. :a; # set label "a"
  4.    n; # read the next line
  5.    /^\|/H; # if the line starts with '|', append the current line to hold space
  6.    /^[^|]/{x;bb}; # if line starts without '|' or reading last line (the next command line), do command "x" to exchange the context in hold space and pattern space, then branch to label "b";
  7.    ${x;bb};
  8. ba; # branch to label "a"
  9. :b; # set label "b";
  10.    s/([^|]+\|([^|]+)\|[^\n]+)(.*)\n\|\2(\|.*)/\1\3\n|\4/; # treat the context in the pattern space by s/// to fit your aim
  11. tb; # if s/// has done successfully, branch to label "b"; otherwise, execute the next command line;
  12. p; # print the context in the pattern space
  13. ba # branch to label "a"
  14. '
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP