如何在 CSV 文件中的字段中添加引号? [英] How can I add quotation marks to fields in a CSV file?
本文介绍了如何在 CSV 文件中的字段中添加引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类似的 CSV 文件
I've got a CSV file like
Brand,Type,Color
Porsche,Sport,Red
BMW,Coupe,Blue
我想包含引号以使其像:
I'd like to include quotation marks to have it like:
"Brand","Type","Color"
"Porsche","Sport","Red"
"BMW","Coupe","Blue"
最快的方法是什么?我将在 cronjob 中实现它.
What's the fastest way to do it? I will implement it in a cronjob.
推荐答案
使用 sed:
sed -e 's/^|$/"/g' -e 's/,/","/g' input
这篇关于如何在 CSV 文件中的字段中添加引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文