开发者

how to replace null value(field) with word on CSV file

I have a comma separated CSV file looks like:

customer1,customer2,,customer4,

,customer开发者_如何转开发2,,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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜