How to remove a character which is enclosed in Double quotes


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to remove a character which is enclosed in Double quotes
# 1  
Old 05-14-2008
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  
Old 05-14-2008
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  
Old 05-14-2008
Another one:

Code:
 awk 'BEGIN{FS="\"";OFS=""}{gsub(",","",$2);gsub(",","",$4)}1' file

Regards
# 4  
Old 06-16-2008
Quote:
Originally Posted by mohan_tuty
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
        }

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

To remove double quotes from specific columns

Hi, I've a requirement like, in a csv file of 30+ fields where all the columns are having double quotes I need to remove the double quotes from certain fields and certain field should remain as it is. Eg:... (6 Replies)
Discussion started by: Krishnanth S
6 Replies

2. Shell Programming and Scripting

Remove pipe(|) symbol in except the ones which are enclosed in double quotes

I have file with are delimited by pipe(|) symbol, I wanted those to be removed except the ones which are enclosed in double quotes. If your quote file is: |Life is |Beautiful"|"Indeed life |is beautiful too|"|"But unix is fun| is not"|" It should return: Life is Beautiful"|"Indeed life is... (9 Replies)
Discussion started by: Sathyapts
9 Replies

3. Shell Programming and Scripting

Remove pipe(|) symbol ina file, except the ones which are enclosed in double quotes

I have file with are delimited by pipe(|) symbol, I wanted those to be removed except the ones which are enclosed in double quotes. If your quote file is: |Life is |Beautiful"|"Indeed life |is beautiful too|"|"But unix is fun| is not"|" It should return: Life is Beautiful"|"Indeed life is... (1 Reply)
Discussion started by: Sathyapts
1 Replies

4. Shell Programming and Scripting

How to delete the commas in a .CSV file that are enclosed in a string with double quotes?

Okay, I would like to delete all the commas in a .CSV file (TEST.CSV) or at least substitute them with empty space, that are enclosed in double quote. Please see the sample file as below: column 1,column 2,column 3,column 4,column 5,column 6,column 7,column 8,column 9,column 10... (8 Replies)
Discussion started by: dhruuv369
8 Replies

5. Shell Programming and Scripting

Trying to remove double quotes

Hi, I am little new to forum and new on unix side. I have a small issue below: I am reading a file that has 5 columns something like below. col1,col2,col3,col4,col5 Some records are having double quoted values something like below: "value1","value2","value3","value4","value5" I need... (8 Replies)
Discussion started by: Saanvi1
8 Replies

6. Shell Programming and Scripting

Replace newline character between a double quotes to a space

Hi Guys, I have a file with content as below aj.txt "Iam allfine" abcdef abcd "all is not well" What I'm trying to say is my data has some new line characters in between quoted text. I must get ride of the newline character that comes in between the quoted text. output must be:... (8 Replies)
Discussion started by: ajahuja
8 Replies

7. UNIX for Dummies Questions & Answers

Remove two delimiters, space and double quotes

I would like to know how to replace a space delimiter with a ^_ (\037) delimiter and a double quote delimiter while maintaining the spaces inside the double quotes. The double quote delimiter is only used on text fields. I'd prefer a one-liner, but could handle a function or script that accepts... (4 Replies)
Discussion started by: SteveDWin
4 Replies

8. Shell Programming and Scripting

How to remove characters enclosed in single quotes?

How to remove characters enclosed in single quotes? My data is something like this (03/22/2011 08:17:26.650) : ( -> '1' -> '1-1-3' -> '6' -> '1' -> 'SALMOR58BB4' aaaaa bbbbbb ccccc ((dddd)) I want the output to be (03/22/2011 08:17:26.650) : ( -> -> -> -> -> aaaaa... (2 Replies)
Discussion started by: rdhanek
2 Replies

9. Shell Programming and Scripting

Removal of new line character in double quotes

Hi, Could you please help me in removal of newline chracter present in between the double quotes and replacing it with space. For example ... Every field is wrapped with double quotes with comma delimiter, so I need to travese from first double quote occerence to till second double... (7 Replies)
Discussion started by: vsairam
7 Replies

10. UNIX for Dummies Questions & Answers

Remove double quotes

A Triva question. What is the easy way to remove the double quotes in the file in the following format. "asdfa","fdgh","qwer" tr -d '\"' <filename >newfilename mv newfilename oldfilename This need to be handled in a script. Any better way to do this. Will sed be more effecient? One... (3 Replies)
Discussion started by: deepakwins
3 Replies
Login or Register to Ask a Question