The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-14-2008
Registered User
 

Join Date: May 2008
Posts: 6
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-14-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,483
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")
       }'
Reply With Quote
  #3 (permalink)  
Old 05-14-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,661
Another one:

Code:
 awk 'BEGIN{FS="\"";OFS=""}{gsub(",","",$2);gsub(",","",$4)}1' file
Regards
Reply With Quote
  #4 (permalink)  
Old 06-16-2008
Registered User
 

Join Date: Apr 2008
Posts: 18
Quote:
Originally Posted by mohan_tuty View Post
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
OK, no matter how many double quotes you have, you always can use the following awk program:
Code:
BEGIN{
        FS="\""
        OFS="\""
        }
        {for(i=1;i<=NF;i++)
                if(i%2 == 0)
                        gsub(/,/, "", $i)
        print
        }
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0