[SPAM] Re: [wplug] awk help

duncanhutty at comcast.net duncanhutty at comcast.net
Fri Aug 27 16:48:01 EDT 2004


How about:
First apply a sed transformation to say that any instance of a comma *inside quotes* were converted to a (pick a suitable escape sequence) and then send it through your awk and then convert all instances of that prior escape sequence back to a commas again.
1st sed command:
/".*"/s/,/\\,/g

Duncan Hutty
-------------- Original message -------------- 

> I am having some issues with parsing a file using awk. I am not sure if awk is 
> the best tool, but I do not know perl at all. I have a comma delimited file 
> that has a few fields quoted. In those quoted fields there are commas. So when 
> awk process those fields it thinks that they are seperate and not one string. 
> i.e. 
> 
> some,text,"is, in",here 
> 
> 
> awk spits out: 
> some 
> text 
> "is 
> in" 
> here 
> 
> I want it to be 
> some 
> text 
> is, in 
> here 
> 
> my awk command is: 
> `cat $1 | awk 'BEGIN{FS=","}{print 
> $1","$3",\""$5"\",\""$6"\","$7","$8","$9","$46","$49}' > output.trans` 
> 
> I haven't found an answer from google. I saw a few people having the same 
> problem. Most just us another language or each field is quote. In that case 
> you can do something like {FS="\",\""} 
> 
> Thanks, 
> Chris 
> 
> _______________________________________________ 
> wplug mailing list 
> wplug at wplug.org 
> http://www.wplug.org/mailman/listinfo/wplug 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://penguin.wplug.org/pipermail/wplug/attachments/20040827/9f3968be/attachment-0001.html


More information about the wplug mailing list