码迷,mamicode.com
首页 > 其他好文 > 详细

如何去掉文本最后一行的最后一个字符

时间:2016-04-28 12:30:18      阅读:389      评论:0      收藏:0      [点我收藏+]

标签:sed

问题:

最近接触文本处理遇见了问题

{"X":40.172819,"Y":116.383621,"Z":.0117,"T":"2016-04-26 16:00:00"},
{"X":39.760256,"Y":116.305211,"Z":.2923,"T":"2016-04-26 16:00:00"},
{"X":39.959291,"Y":116.32090099999999,"Z":.3288,"T":"2016-04-26 16:00:00"},
{"X":40.019980999999994,"Y":116.339131,"Z":.2475,"T":"2016-04-26 16:00:00"},
{"X":39.983142,"Y":116.303713,"Z":1.155,"T":"2016-04-26 16:00:00"},

现在我想把最后一行结尾的逗号(,)去掉


解答:

sed ‘s/.$//‘ file
{"X":40.172819,"Y":116.383621,"Z":.0117,"T":"2016-04-26 16:00:00"}
{"X":39.760256,"Y":116.305211,"Z":.2923,"T":"2016-04-26 16:00:00"}
{"X":39.959291,"Y":116.32090099999999,"Z":.3288,"T":"2016-04-26 16:00:00"}
{"X":40.019980999999994,"Y":116.339131,"Z":.2475,"T":"2016-04-26 16:00:00"}
{"X":39.983142,"Y":116.303713,"Z":1.155,"T":"2016-04-26 16:00:00"}

awk ‘{sub(/.$/,"")}1‘ file
{"X":40.172819,"Y":116.383621,"Z":.0117,"T":"2016-04-26 16:00:00"}
{"X":39.760256,"Y":116.305211,"Z":.2923,"T":"2016-04-26 16:00:00"}
{"X":39.959291,"Y":116.32090099999999,"Z":.3288,"T":"2016-04-26 16:00:00"}
{"X":40.019980999999994,"Y":116.339131,"Z":.2475,"T":"2016-04-26 16:00:00"}
{"X":39.983142,"Y":116.303713,"Z":1.155,"T":"2016-04-26 16:00:00"}

本文出自 “八英里” 博客,请务必保留此出处http://5921271.blog.51cto.com/5911271/1768487

如何去掉文本最后一行的最后一个字符

标签:sed

原文地址:http://5921271.blog.51cto.com/5911271/1768487

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!