问题:
最近接触文本处理遇见了问题
{"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"}