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

xsv table and double quotes in text fields #67

Open
sandman7920 opened this issue Mar 28, 2017 · 7 comments
Open

xsv table and double quotes in text fields #67

sandman7920 opened this issue Mar 28, 2017 · 7 comments

Comments

@sandman7920
Copy link

Is there any way to show double quotes as a single quote symbol

Test:

echo '1,"Test ""22"""'|xsv table -p 10

Result:

1           "Test ""22"""

Wanted:

1           Test "22"
@BurntSushi
Copy link
Owner

No. But this actually seems sensible to do.

@sandman7920
Copy link
Author

sandman7920 commented Mar 28, 2017

table and flatten commands are human readable formatters.
Flatten format output data correct

table:

echo -en '"ID","TEXT"\n1,"Test ""22"""'|xsv table
ID  TEXT
1   "Test ""22"""

flatten:

echo -en '"ID","TEXT"\n1,"Test ""22"""'|xsv flatten
ID    1
TEXT  Test "22"

@sandman7920
Copy link
Author

sandman7920 commented Mar 28, 2017

The basic idea is to do something like:

xsv table <filename|less -SN -#3

and then you can use less functionality (search, scroll, etc)

@BurntSushi
Copy link
Owner

Right. I get it. The reason why it doesn't work today is because xsv table is actually using a CSV writer to write the contents. I think that just needs to be changed to writing tab-delimited fields (which get auto-aligned by the underlying elastic tabstop writer).

@unhammer
Copy link

unhammer commented Apr 5, 2019

Similarly for fmt:

$ printf 'user\tutterance\njoe\tSay "hi"\n'
user    utterance
joe     Say "hi"

$ printf 'user\tutterance\njoe\tSay "hi"\n'|xsv select -d $'\t' utterance
utterance
"Say ""hi"""

$ printf 'user\tutterance\njoe\tSay "hi"\n'|xsv select -d $'\t' utterance|xsv fmt -t $'\t'
utterance
"Say ""hi"""

# Or even:
$ printf 'Say "hi"\n'|xsv fmt -d $'\t' -t $'\t'
"Say ""hi"""

Since tab-separated files don't tend to have double quotes like CSV's, it'd be nice to be able to strip them and simply get back

$ printf 'user\tutterance\njoe\tSay "hi"\n'|xsv select -d $'\t' utterance|xsv fmt -t $'\t'
utterance
Say "hi"

but since --quote requires a single ASCII character, there doesn't seem to be a way to do that:

$ printf 'user\tutterance\njoe\tSay "hi"\n'|xsv select -d $'\t' utterance|xsv fmt --quote $'\0' -t $'\t'
Could not convert '' to a single ASCII character.

@unhammer
Copy link

unhammer commented Apr 5, 2019

Oh, wait, this UNDOCUMENTED HACK seems to work for some reason:

$ printf 'user\tutterance\njoe\tSay "hi"\n'|xsv select -d $'\t' utterance|xsv fmt --quote $'\1' -t $'\t'
utterance
Say "hi"

and it's not in the output:

printf 'user\tutterance\njoe\tSay "hi"\n'|xsv select -d $'\t' utterance|xsv fmt --quote $'\1' -t $'\t' | grep -c $'\1'
0

@BurntSushi
Copy link
Owner

@unhammer Sorry, but that's completely unrelated to this issue. This issue is about xsv table, but you're talking about xsv fmt. Please open a new bug.

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

No branches or pull requests

3 participants