1

Possible Duplicate:
Remove comma between the quotes only

I'm trying to use awk function to replace the semicolons between quotes to comma and it is 98% ok for me, because I want to keep the quotes (“”).

Input string

0x0001003C00040B40;1674901;3;3;"PORTUGAL,0x7ed78c,0x285d";1;12;5;5;;;"SIP,[email protected],;tag=gK06033793,,0,,,,sip:5343559563@213:5060,213379902684@213,,,sip:213379902684@213:5060,,,,,,403,21,0,0,,0,0,,,,,,,,1,0,0,0,,";213379902684;;110;;;1;1;;;3;C:1:2;;;0x3D064F1D;0;1;;0;;;;;;0;;;;;;;;;;;14;;;;;;1;1;1;1;;1;3;3;;7;;;1;21;;;;;;16;8;3;;;;;;"REDI,20,3459,3459,0,0,1,1,1,2,,,,,,,,,,,0,2";;1;;2;TANDEM;;;;;;;;;;;;;;;;;;;22;16;;;;;;1;;;;;;;;;;;;;;;;;0;9;9;;8312716;10333;;;;;;;;;;;"0,495,0,0";0;;;;;;;;;;;;;;;;;;;;;;;831271610333;

Code

/usr/xpg4/bin/awk -F'"' -v OFS='' '{ for (i=2; i<=NF; i+=2) gsub(";", ",", $i) } 1' infile

Actual result

0x0001003C00040B40;1674901;3;3;PORTUGAL,0x7ed78c,0x285d;1;12;5;5;;;SIP,[email protected],,tag=gK06033793,,0,,,,sip:5343559563@213:5060,213379902684@213,,,sip:213379902684@213:5060,,,,,,403,21,0,0,,0,0,,,,,,,,1,0,0,0,,;213379902684;;110;;;1;1;;;3;C:1:2;;;0x3D064F1D;0;1;;0;;;;;;0;;;;;;;;;;;14;;;;;;1;1;1;1;;1;3;3;;7;;;1;21;;;;;;16;8;3;;;;;;REDI,20,3459,3459,0,0,1,1,1,2,,,,,,,,,,,0,2;;1;;2;TANDEM;;;;;;;;;;;;;;;;;;;22;16;;;;;;1;;;;;;;;;;;;;;;;;0;9;9;;8312716;10333;;;;;;;;;;;0,495,0,0;0;;;;;;;;;;;;;;;;;;;;;;;831271610333;

Wanted result

0x0001003C00040B40;1674901;3;3;"PORTUGAL,0x7ed78c,0x285d";1;12;5;5;;;"SIP,[email protected],,tag=gK06033793,,0,,,,sip:5343559563@213:5060,213379902684@213,,,sip:213379902684@213:5060,,,,,,403,21,0,0,,0,0,,,,,,,,1,0,0,0,,";213379902684;;110;;;1;1;;;3;C:1:2;;;0x3D064F1D;0;1;;0;;;;;;0;;;;;;;;;;;14;;;;;;1;1;1;1;;1;3;3;;7;;;1;21;;;;;;16;8;3;;;;;;"REDI,20,3459,3459,0,0,1,1,1,2,,,,,,,,,,,0,2";;1;;2;TANDEM;;;;;;;;;;;;;;;;;;;22;16;;;;;;1;;;;;;;;;;;;;;;;;0;9;9;;8312716;10333;;;;;;;;;;;"0,495,0,0";0;;;;;;;;;;;;;;;;;;;;;;;831271610333;

How can I do that?

filipe
  • 11
  • 3

1 Answers1

3

Just use " as the output field separator.

awk -F\" -v OFS=\" '{ for (i=2; i<=NF; i+=2) gsub(";", ",", $i) } 1'
Chris Down
  • 122,090
  • 24
  • 265
  • 262
  • Hi Chris, thank you for your answer. I used: awk -F'"' -v OFS='"' '{ for (i=2; i<=NF; i+=2) gsub(";", ",", $i) } 1' and it worked!!! :) – filipe Nov 22 '12 at 19:06