![]() |
|
|
|
|
|||||||
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Remove double quotes | deepakwins | UNIX for Dummies Questions & Answers | 3 | 05-30-2008 08:53 AM |
| Double quotes or single quotes when using ssh? | password636 | Shell Programming and Scripting | 3 | 05-29-2008 05:52 PM |
| put double quotes for a column | sumeet | Shell Programming and Scripting | 3 | 05-09-2007 04:20 PM |
| How do I insert double quotes | dsean | Shell Programming and Scripting | 3 | 05-26-2006 10:28 AM |
| Double Quotes within a variable | burton_1080 | Shell Programming and Scripting | 4 | 12-01-2005 09:44 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
How to remove a character which is enclosed in Double quotes
I want to remove the comma which is present within the double quoted string. All other commas which is present outside double quotes should be present.
Input : a,b,"cc,dd,ee",f,ii,"jj,kk",mmm output : a,b,"ccddee",f,ii,"jjkk",mmm |
| Forum Sponsor | ||
|
|
|
|||
|
one long-winded way with awk:
Code:
echo 'a,b,"cc,dd,ee",f,ii,"jj,kk",mmm' | \
awk -v sep='"' '{
for(i=1;i<=length($0); i++)
{
ch=substr($0,i,1)
if(ch==sep) {inside=!inside}
if (inside && ch==",") {continue}
printf("%s",ch)
}
printf("\n")
}'
|
|
|||
|
Quote:
Code:
BEGIN{
FS="\""
OFS="\""
}
{for(i=1;i<=NF;i++)
if(i%2 == 0)
gsub(/,/, "", $i)
print
}
|
|||
| Google UNIX.COM |
| Thread Tools | |
| Display Modes | |
|
|