如何使用awk在列周围添加单引号 [英] How to add single quotes around columns using awk
本文介绍了如何使用awk在列周围添加单引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只是想知道如何在字段周围添加单引号,因此我可以将其导入到mysql中而不会发出警告或错误.
Just wondering how can I add single quotes around fields, so I can import it to mysql without warnings or errors.
我有一个内容丰富的csv文件.
I have a csv file with lots of content.
16:47:11,3,r-4-VM,250000000.,0.50822578824,131072,0,0,0,0,0
所需的输出
'16:47:07','3','r-4-VM','230000000.','0.466028518635','131072','0','0','0','60','0'
我真的不知道从哪里开始,非常感谢您的帮助.
I really have no idea where to start, your help is highly appreciated.
推荐答案
您可以尝试
awk -F"," -v quote="'" -v OFS="','" '$1=$1 {print quote $0 quote}' file
- 将每个分隔符(,逗号)替换为(','quote-逗号-quote)->
(-F"," -v OFS="','")
- 在行的开头和结尾添加引号->
(print quote $0 quote)
- Replace each separator (, comma) with (',' quote-comma-quote) ->
(-F"," -v OFS="','")
- Add quotes to the begin and end of line ->
(print quote $0 quote)
这篇关于如何使用awk在列周围添加单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文