如何更换空值(场)对CSV文件字 [英] how to replace null value(field) with word on CSV file

查看:124
本文介绍了如何更换空值(场)对CSV文件字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个逗号分隔的CSV文件看起来像:

 的customer1,customer2表,customer4,,的customer2,customer4,custome1,customer3 ,,

我想与字代替空值内(,)未知。

我怎么能这样做?


解决方案

 的sed -e'S / ,, /,未知/ G'

将工作,如果你想在太行的开头或结尾添加未知的情况除外。

如果你也想补充一点,如果第一丢失(符合开始,)或最后一个失踪(符合结束),那么你可以这样做:

 的sed -e'S / ^ /未知,/'-e'S / ,, /,未知/ G'-e'S /,$ /未知/ 

我敢肯定有一个更优雅的方式,但此工作。

I have a comma separated CSV file looks like:

customer1,customer2,,customer4,

,customer2,,customer4,

custome1,,customer3,,

I want replace null value inside (,)with word "unknown".

How can I do that?

解决方案

sed -e 's/,,/,unknown,/g'

will work except if you want to add unknown at the beginning or end of lines too.

If you also want to add something if the first is missing (line starts with ,) or the last one is missing (line ends with ,), then you could do:

sed -e 's/^,/unknown,/' -e 's/,,/,unknown,/g' -e 's/,$/,unknown/'

I'm sure there is a more elegant way, but that works.

这篇关于如何更换空值(场)对CSV文件字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆