comma in csv file is recognized as separator even though it's inside double quote

amu03 :

I am struggling for 2 days...Does anyone have any idea why this happens?

What I did:

I've exported some data as csv file (mysql). It's separated by comma, enclosed by double quotes.

the query looks like..

select * from table1 
INTO OUTFILE 'sample.csv'
CHARACTER SET utf8
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\r\n';

and this is what sample.csv looks like:

"post_name","post_title","post_date","post_thumbnail","post_mainimage","post_content,"meta_description","text2","editor_id"
    "post1","title!|this is title","1451905200","123.jpg","123.jpg","<p>this is description</p> <h2> this is description <br>\"this is description \"</h2><p><span style=\"line-height: 1.8;\">「this is description」</span></p><p><img alt=\"aa,bb,cc \" class=\"fr-fin fr-dib\" src=\"/files/123.jpg\" title=\"aa,bb,cc \" width=\"300\"></p><p>this is description</p><p><strong>this is description</strong></p><p><span style=\"font-size: 13px;\">this is description<br>this is description</span><br></p>","this is meta_description","this is text2","12"

Problem:

when I open this file on Mac Numbers (and other csv viewers as well), it seems like comma after 'aa' is recognized as separator, and therefore 'bb' is placed in the next cell in the table, which is unexpected result because I thought that comma inside double quote wouldn't be treated as separator.

Any advice and help will be greatly appreciated!

edit:

I accidentally deleted double quote while I editing. so "post_content was actually "post_content"

thanks for the comments!! I will read through when I get home!

Danny_ds :

First, there is a double quote missing in the header:

,"post_content,

Second, it looks like the parser doesn't see the \ as an escape for the embedded double quotes.

Using \" is 'Linux style', where "" is 'Windows style'. Your data also uses \r\n which is Windows style - so maybe the parser is confused?

Anyway, you should tell the parser to use \ as escape character, or just use " as the escape character when exporting.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to escape comma and double quote at same time for CSV file?

How to read pandas CSV file with comma separator and comma thousand separator

Replacing comma if found inside double quotations in a CSV file using sed

In Window Batch - how do I parse CSV file where fields include Comma and double quote

Namespace not recognized (even though it is there)

How to preserve `backticks` in R's quote() even though not needed?

Adding double quote delimiters into csv file

awk double quote field separator

missing jquery even though it is inside file laravel

Read a csv that has double quotes with comma inside

parse double from file with random comma or dot separator

How to write to a file using comma delimiter and no double quote in string?

Python: Load a csv file in a DataFrame with exception for string and list comma separator

How to check if .csv-File has a comma or a semicolon as separator?

How to read a CSV file in Pandas with quote characters and comma?

Git says a file is modified even though it's not

Valid CSV filed import fails with Data between close double quote (") and field separator: field starts with

c# join string comma delimited, but double quote all values inside

C# Regex Pattern to remove comma inside double quote delimited string

(sed) Remove comma between any two numbers inside double quote (but keep the number)

HTML file shows blank screen even though it has content inside it

How to escape quote inside a double-quote?

CSV file not found even though it exists (FileNotFound [Errno 2])

wget is not recognized as a command even though it is installed

How can I quote text that's already inside a single and double quote?

Property recognized as undefined in spec file even though it exist in the component. Unit Test in Angular with Karma - Jasmine

Swift – String with comma-separator to double

Convert a double to 2 decimal places with comma separator

Comma separated value within double quote

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive