bash - How to make awk ignore the field delimiter inside double quotes? -
this question has answer here:
i need delete 2 columns in comma seperated values file. consider following line in csv file:
"abc@xyz.com,www.example.com",field2,field3,field4 "def@xyz.com",field2,field3,field4
now, result want @ end:
"abc@xyz.com,www.example.com",field4 "def@xyz.com",field4
i used following command:
awk 'begin{fs=ofs=","}{print $1,$4}'
but embedded comma inside quotes creating problem, following result getting:
"abc@xyz.com,field3 "def@xyz.com",field4
now question how make awk ignore "," inside double quotes?
from gnu awk manual (http://www.gnu.org/software/gawk/manual/gawk.html#splitting-by-content):
$ awk -vfpat='([^,]*)|("[^"]+")' -vofs=, '{print $1,$4}' file "abc@xyz.com,www.example.com",field4 "def@xyz.com",field4
and see what's robust way efficiently parse csv using awk? more parsing csvs include newlines, etc. within fields.
Comments
Post a Comment