Sponsored Content
Top Forums Shell Programming and Scripting Removal of comma within double quotes Post 302968627 by H_bansal on Friday 11th of March 2016 06:04:07 PM
Old 03-11-2016
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
Code:
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
Code:
abc,123,xxyy,2178
fgh,123,xx"yy,2178
ghi,123,xxyy,2178
jkl,123,xx"yy,2178

I ran the following code

Code:
 
 awk -F'"' -v OFS='' '{ for (i=2; i<=NF; i+=2) gsub(",", "", $i) } 1' test.csv

If quotes are unbalanced it removes all the valid commas after it finds first quotes.
Can you please help me with this.

Thanks,
Bansal

Last edited by Scrutinizer; 03-12-2016 at 05:09 AM.. Reason: code tags, removed "LEFT" formatting
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed removing comma inside double quotes

I have a csv file with lines like the followings 123456,"ABC CO., LTD","XXX" 789012,"DEF LIMITED", "XXX" before I bcp this file to database, the comma in "CO.," need to be removed first. My script is cat <filename> | sed 's/"CO.,"/"CO."/g' but it doesn't work. Can anyone here able to... (2 Replies)
Discussion started by: joanneho
2 Replies

2. Shell Programming and Scripting

To Replace comma with Pipe inside double quotes

Hi, I have a requirement to replace the comma's inside the double quotes. The comma's inside the double quotes will get changed dynamically. Input Record: "Washington, DC,Prabhu,aju",New York Output Record: "Washington| DC|Prabhu|aju",New York I tried with the below command but it... (3 Replies)
Discussion started by: prabhutkl
3 Replies

3. Shell Programming and Scripting

Removal of comma(,) present inbetween double quotes(" ")

Hi Experts, I have a file with some of the records contain double quotes. If I found a double quote(") in any particular record , I need to look for the next double quote in that particular record and in between these quotes, if any comma(,) is there I need to replace with Tilde (~) in the same... (12 Replies)
Discussion started by: vsairam
12 Replies

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

5. Shell Programming and Scripting

awk, comma as field separator and text inside double quotes as a field.

Hi, all I need to get fields in a line that are separated by commas, some of the fields are enclosed with double quotes, and they are supposed to be treated as a single field even if there are commas inside the quotes. sample input: for this line, 5 fields are supposed to be extracted, they... (8 Replies)
Discussion started by: kevintse
8 Replies

6. Shell Programming and Scripting

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 "Chapter","NewTrains, "oldTrains","Delayed",10,"London" "Chapter","Newbuses,oldbuses","On Time",20,"London" Output "Chapter","NewTrainsDSEE?DSEE... (5 Replies)
Discussion started by: venkatvani
5 Replies

7. Shell Programming and Scripting

awk print - fields separated with comma's need to ignore inbetween double quotes

I am trying to re-format a .csv file using awk. I have 6 fields in the .csv file. Some of the fields are enclosed in double quotes and contain comma's inside the quotes. awk is breaking this into multiple fields. Sample lines from the .csv file: Device Name,Personnel,Date,Solution... (1 Reply)
Discussion started by: jxrst
1 Replies

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

9. Shell Programming and Scripting

Removal of multiple characters with in double quotes

For one of my need I was going through post "Removal of new line character in double quotes" Which alister has replied like $ cat data "leave me alone" "ABCD RENT-A- CAR XYZ LTD","00N0H","Enterprise Lake"," 100 View Way" $ sed -n 'H;g;/^*"*\("*"*\)*$/d; s/^\n//; y/\n/ /; p; s/.*//; h'... (9 Replies)
Discussion started by: Jag_1981
9 Replies

10. 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
DBLINK_GET_PKEY(3)					  PostgreSQL 9.2.7 Documentation					DBLINK_GET_PKEY(3)

NAME
dblink_get_pkey - returns the positions and field names of a relation's primary key fields SYNOPSIS
dblink_get_pkey(text relname) returns setof dblink_pkey_results DESCRIPTION
dblink_get_pkey provides information about the primary key of a relation in the local database. This is sometimes useful in generating queries to be sent to remote databases. ARGUMENTS
relname Name of a local relation, for example foo or myschema.mytab. Include double quotes if the name is mixed-case or contains special characters, for example "FooBar"; without quotes, the string will be folded to lower case. RETURN VALUE
Returns one row for each primary key field, or no rows if the relation has no primary key. The result row type is defined as CREATE TYPE dblink_pkey_results AS (position int, colname text); The position column simply runs from 1 to N; it is the number of the field within the primary key, not the number within the table's columns. EXAMPLES
CREATE TABLE foobar ( f1 int, f2 int, f3 int, PRIMARY KEY (f1, f2, f3) ); CREATE TABLE SELECT * FROM dblink_get_pkey('foobar'); position | colname ----------+--------- 1 | f1 2 | f2 3 | f3 (3 rows) PostgreSQL 9.2.7 2014-02-17 DBLINK_GET_PKEY(3)
All times are GMT -4. The time now is 12:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy