The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

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 11:53 AM
Double quotes or single quotes when using ssh? password636 Shell Programming and Scripting 3 05-29-2008 08:52 PM
put double quotes for a column sumeet Shell Programming and Scripting 3 05-09-2007 07:20 PM
How do I insert double quotes dsean Shell Programming and Scripting 3 05-26-2006 01:28 PM
Double Quotes within a variable burton_1080 Shell Programming and Scripting 4 12-01-2005 01:44 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-14-2008
mohan_tuty mohan_tuty is offline
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
  #2 (permalink)  
Old 05-14-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
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")
       }'
  #3 (permalink)  
Old 05-14-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,294
Another one:

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

Join Date: Apr 2008
Posts: 38
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
        }
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:20 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0