Replacing comma with in double quotes in a csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing comma with in double quotes in a csv file
# 1  
Old 02-14-2011
Replacing comma with in double quotes in a csv file

Hello,
I need to read a csv file and I am trying to replace a comma with a text DSEE?DSEE.

Example
Input
Code:
"Chapter","NewTrains, "oldTrains","Delayed",10,"London"
"Chapter","Newbuses,oldbuses","On Time",20,"London"

Output
Code:
"Chapter","NewTrainsDSEE?DSEE "oldTrains","Delayed",10,"London"
"Chapter","NewbusesDSEE?DSEEoldbuses","On Time",20,"London"

The reason I am replacing with DSEE?DSEE is because after processing this file I will be replacing this back with a comma

Any help would be appreciated!

Regards,
Ven
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 02-14-2011 at 12:07 PM.. Reason: code tags, please!
# 2  
Old 02-14-2011
Code:
sed 's/,/DSEE?DSEE/2' infile

you also could try :

Code:
sed 's:\("[^",][^",]*\),\([^",][^",]*"\):\1DSEE?DSEE\2:g' infile


Last edited by ctsgnb; 02-14-2011 at 12:31 PM..
# 3  
Old 02-14-2011
Question

Can you take a look at your first line, I am confused if all the double-quotes match up as you intend. I am counting an odd number.
# 4  
Old 02-14-2011
HI Joeyg

In the source file there could be double quote with in the data, if the previous example is confusing
Input
Code:
"Chapter","NewTrains "oldTrains","Delayed",10,"London"
"Chapter","Newbuses,oldbuses","On Time",20,"London"

Output
Code:
"Chapter","NewTrains "oldTrains","Delayed",10,"London"
"Chapter","NewbusesDSEE?DSEEoldbuses","On Time",20,"London"


Last edited by Scott; 02-14-2011 at 01:00 PM.. Reason: Code tags
# 5  
Old 02-14-2011
See if it works for you
Code:
sed 's/\([a-zA-Z]\),/\1DSEE?DSEE/' input_file

# 6  
Old 02-14-2011
also
Code:
sed 's:\("[^",][^",]*\),:\1DSEE?DSEE:g' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to parse comma separated field and removing comma in between number and double quotes

Hi Experts, Please support I have below data in file in comma seperated, but 4th column is containing comma in between numbers, bcz of which when i tried to parse the file the column 6th value(5049641141) is being removed from the file and value(222.82) in column 5 becoming value of column6. ... (3 Replies)
Discussion started by: as7951
3 Replies

2. Shell Programming and Scripting

sed add double quotes and comma

Hi, 00000119EEEC3F25 feedoor 20171103 0000011A4F152077 feedard 20171024 00000191FA295F61 feedzipperhola 20171023 00000213C57BB856 feedriodapple 20171005 0000025F778EF9D5 joobakoolrk 20171004 I needed the result as: "00000119EEEC3F25", "feedoor", ... (9 Replies)
Discussion started by: ashokvpp
9 Replies

3. Shell Programming and Scripting

Removal of comma within double quotes

Hi All, I am getting .csv file whenever there is a comma present between a field that field get enclosed with double quotes For eg as below abc,123,xxyy,2178 fgh,123,"x,x"yy",2178 ghi,123,"x,xyy",2178 jkl,123,xx"yy,2178 whereas I want my data as per below abc,123,xxyy,2178... (1 Reply)
Discussion started by: H_bansal
1 Replies

4. Shell Programming and Scripting

Replace Double quotes within double quotes in a column with space while loading a CSV file

Hi All, I'm unable to load the data using sql loader where there are double quotes within the double quotes As these are optionally enclosed by double quotes. Sample Data : "221100",138.00,"D","0019/1477","44012075","49938","49938/15043000","Television - 22" Refurbished - Airwave","Supply... (6 Replies)
Discussion started by: mlavanya
6 Replies

5. Shell Programming and Scripting

Shell script that should remove unnecessary commas between double quotes in CSV file

i have data as below 123,"paul phiri",paul@yahoo.com,"po.box 23, BT","Eco Bank,Blantyre,Malawi" i need an output to be 123,"paul phiri",paul@yahoo.com,"po.box 23 BT","Eco Bank Blantyre Malawi" (5 Replies)
Discussion started by: mathias23
5 Replies

6. 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

7. Shell Programming and Scripting

Need Help - comma inside double quote in comma separated csv,

Hello there, I have a comma separated csv , and all the text field is wrapped by double quote. Issue is some text field contain comma as well inside double quote. so it is difficult to process. Input in the csv file is , 1,234,"abc,12,gh","GH234TY",34 I need output like below,... (8 Replies)
Discussion started by: Uttam Maji
8 Replies

8. Shell Programming and Scripting

HELP with AWK or SED. Need to replace the commas between double quotes in CSV file

Hello experts, I need to validate a csv file which contains data like this: Sample.csv "ABCD","I",23,0,9,,"23/12/2012","OK","Street,State, 91135",0 "ABCD","I",23,0,9,,"23/12/2012","OK","Street,State, 91135",0 I just need to check if all the records contain exactly the number of... (5 Replies)
Discussion started by: shell_boy23
5 Replies

9. UNIX for Advanced & Expert Users

Replacing the comma in .csv file in unix

Hi All, Could some one help me on one of my requirement below: I have a sequential file with 4fields in it and it is a comma (,) seperated file. Delimeter is 'comma'. But in of the file column for ex: 3rd column it is 'Description' (column name) I am getting the values with commas.... (6 Replies)
Discussion started by: eskay_s
6 Replies

10. Shell Programming and Scripting

replace value with double quotes of specific coulmn value in csv file

Hi, I am trying to replace a specific column values in a csv file with double quotes. Example: SNO,NAME,ZIPCODE,RANK 1,Robert,74538,12 2,Sam,07564,13 3,Kim, Ed,12345,14 Desired Output: SNO,NAME,ZIPCODE,RANK 1,Robert Ken,74538,12 2,Sam Mik,"07564",13 3,"Kim, Ed",12345,14 I... (3 Replies)
Discussion started by: techmoris
3 Replies
Login or Register to Ask a Question