Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--lazy-quotes does not work for fields starting with quotes but not ending with #260

Closed
shenwei356 opened this issue Nov 24, 2023 · 1 comment

Comments

@shenwei356
Copy link
Owner

$ echo -ne "a,\"Cellvibrio\" Winogradsky 1929,c\n" 
a,"Cellvibrio" Winogradsky 1929,c

$ echo -ne "a,\"Cellvibrio\" Winogradsky 1929,c\n" | csvtk pretty -l
a   Cellvibrio" Winogradsky 1929,c 
-   -------------------------------

# `csvtk fix` did not fix this.
$ echo -ne "a,\"Cellvibrio\" Winogradsky 1929,c\n" | csvtk fix -l | csvtk pretty -l
[INFO] the maximum number of columns in all 1 rows: 2
a   Cellvibrio" Winogradsky 1929,c 
-   -------------------------------

However, when the quotes are only in the middle of fields, theres' no problem.

$ echo -ne "a,Cellvibrio\" Winogradsky 1929,c\n"
a,Cellvibrio" Winogradsky 1929,c
$ echo -ne "a,Cellvibrio\" Winogradsky 1929,c\n" | csvtk pretty -l
a   Cellvibrio" Winogradsky 1929   c
-   ----------------------------   -

According to this answer, the CSV format is not valid ~

@shenwei356
Copy link
Owner Author

shenwei356 commented Nov 24, 2023

Added two commands:

  • fix-quotes: fix malformed CSV/TSV caused by double-quotes.
  • del-quotes: remove extra double-quotes added by `fix-quotes

Try it:

$ echo -ne "a,\"Cellvibrio\" Winogradsky 1929,c\n" 
a,"Cellvibrio" Winogradsky 1929,c

$ echo -ne "a,\"Cellvibrio\" Winogradsky 1929,c\n"  | csvtk fix-quotes | csvtk cut -f 1-
a,"""Cellvibrio"" Winogradsky 1929",c

$ echo -ne "a,\"Cellvibrio\" Winogradsky 1929,c\n"  | csvtk fix-quotes | csvtk pretty 
a   "Cellvibrio" Winogradsky 1929   c
-   -----------------------------   -

$ echo -ne "a,\"Cellvibrio\" Winogradsky 1929,c\n"  | csvtk fix-quotes | csvtk del-quotes 
a,"Cellvibrio" Winogradsky 1929,c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant