News for hackers. Stuff that matters.
Re:How to Analyze Every Reddit Submission and Comment, in Se... by astazangasta on Saturday October 03, 2015 @01:09PM (#10324523)
Question: why the hell do people use CSVs? Use tabs, goddammit. Documents are littered with commas. It's trivial to parse a TSV with awk - not so a CSV. There is literally no reason to prefer CSV to TSV, and yet it seems the former is the default for many people. Why? As a guy who parses text files all day, I never ever want to see a CSV again. End rant.
Re:How to Analyze Every Reddit Submission and Comment, in Se... by minimaxir on Saturday October 03, 2015 @01:17PM (#10324557)
Pretty much every programming language in existence has a utility for parsing CSVs into tabular data while handling commas sanely. (using awk for processing is not a typical pipeline)

More importantly, CSVs are handled natively by statistical programs such as Excel and R (you can change the expected delimiter while importing, but in my experience that leads to unexpected results)

Re:How to Analyze Every Reddit Submission and Comment, in Se... by Pxtl on Saturday October 03, 2015 @02:10PM (#10324792)
Microsoft often fails with CSVs actually. I've found I can't copy/paste from Sql Server Management Studio into Excel if you have a mismatched double-quote in a cell - it fails silently and garbles your data.

That was embarrassing.

The CSV format is so messy that even big corporate implementations will have subtle bugs like that. Do not trust it.

Re:How to Analyze Every Reddit Submission and Comment, in Se... by 0x0 on Saturday October 03, 2015 @03:08PM (#10324991)
Microsoft excel has the worst CSV defaults. The separating character is even locale-specific! Many locales use semicolon ";" instead of "," as a separator. Great stuff when creating web app exporters.
Re:How to Analyze Every Reddit Submission and Comment, in Se... by hiperlink on Saturday October 03, 2015 @03:05PM (#10324976)
> using awk for processing is not a typical pipeline

except it is. (g)awk is more often part of the pipe(d)line than other programming langueage(s) interpreter(s).

Re:How to Analyze Every Reddit Submission and Comment, in Se... by gruez on Saturday October 03, 2015 @01:35PM (#10324623)
>More importantly, CSVs are handled natively by statistical programs such as Excel and R

in excel or R? Because I've never encountered problems with tsv files with excel

Re:How to Analyze Every Reddit Submission and Comment, in Se... by semi-extrinsic on Saturday October 03, 2015 @02:06PM (#10324765)
R can also read both CSV and TSV just fine. Just use read.csv() or read.table() as you want. Same goes for Pandas.
Re:How to Analyze Every Reddit Submission and Comment, in Se... by muddi900 on Saturday October 03, 2015 @02:51PM (#10324940)
Excel can handle TSV's if you name them .txt
Re:How to Analyze Every Reddit Submission and Comment, in Se... by dorfsmay on Saturday October 03, 2015 @01:20PM (#10324568)
Network effect: Database upload/export, spreadsheets, etc... I used to hate them too until I realized how ubiquitous and well supported they are.

comma vs. tab: It doesn't matter, in the end, you have to use a character to separate fields, and if you are going to use a "normal" character, there are chances that it might appear in your text, so you have to either escape that character, or quote your text, which csv does in a fairly standard way, so comma vs tab doesn't really matter.

Re:How to Analyze Every Reddit Submission and Comment, in Se... by username223 on Saturday October 03, 2015 @04:25PM (#10325218)
> ... if you are going to use a "normal" character, ...

It's a shame that the ASCII file, group, record, and unit separators that have been around since forever did not catch on.

Re:How to Analyze Every Reddit Submission and Comment, in Se... by Rotten194 on Saturday October 03, 2015 @06:14PM (#10325584)
Mostly because they aren't user-inputtable. Yes you can't realistically hand-edit a 3gb .csv either, but csvs don't usually start out that large.
Re:How to Analyze Every Reddit Submission and Comment, in Se... by username223 on Saturday October 03, 2015 @09:10PM (#10326004)
I was going to add a sentence to my comment... They were easy to input via control-caret, etc., until various programs repurposed those combinations. I think a bigger problem is that there is no standard way to display them.

(BTW, if inputtability mattered at all, Unicode wouldn't exist. ;-)

Re:How to Analyze Every Reddit Submission and Comment, in Se... by e12e on Sunday October 04, 2015 @01:34AM (#10326604)
I'm not sure what you mean by your last sentence. Sure, you might have to work a bit to be able to change your locale to Klingon, and input that -- but for something for which unicode is actually useful, like Japanese, there's been input solutions for a long time (predating unicode, as you need a wide character set for such languages).

And unicode is of course easy to use with "less exotic" languages like Norwegian that can't be represented in basic 127-bit ascii -- via a simple keyboard map.

Re:How to Analyze Every Reddit Submission and Comment, in Se... by infecto on Saturday October 03, 2015 @02:05PM (#10324763)
+1

I always found it best practice to quote text. Makes the debate a moot point.

Re:How to Analyze Every Reddit Submission and Comment, in Se... by andreasvc on Saturday October 03, 2015 @01:23PM (#10324575)
I can think of at least one reason. Copy-pasting from a terminal fails to preserve tabs, while commas are fine.

Tabs might be somewhat less frequent than commas in data, but you're still gonna have just as bad a time when they do turn up. And don't forget quoting and escaping. Without proper parsing you can neither read CSV nor TSV safely. My go to solution is pandas.read_table()

Re:How to Analyze Every Reddit Submission and Comment, in Se... by danso on Saturday October 03, 2015 @02:08PM (#10324780)
Yeah, this is the deciding factor for me, too. The point of delimited text files is to find some compromise between machine-efficency and human readability. CSVs are generally much less readable than TSVs, but have less ambiguity, too. With TSVs, it's hard to tell if a tab space is actually a tab or just multiple spaces.

And with developers (especially Python devs) setting their text editors to translate tabs-into-spaces, copy-pasting TSVs results in data corruption. Or even opening a TSV in your text editor with default settings.

Re:How to Analyze Every Reddit Submission and Comment, in Se... by devit on Saturday October 03, 2015 @03:04PM (#10324974)
Good terminal applications such as Gnome Terminal preserve tabs.
Re:How to Analyze Every Reddit Submission and Comment, in Se... by mbell on Saturday October 03, 2015 @03:08PM (#10324989)
> Use tabs, goddammit.

Use ASCII's `RECORD`, `GROUP` and `UNIT` separators, they were literally designed for it.

Re:How to Analyze Every Reddit Submission and Comment, in Se... by hueving on Saturday October 03, 2015 @08:25PM (#10325941)
Which key to I press on the keyboard for those when I want to hand edit docs for quick testing?
Re:How to Analyze Every Reddit Submission and Comment, in Se... by mbell on Saturday October 03, 2015 @09:31PM (#10326037)
In terminal / vim:

    Record separator => C-v C-^
    Unit separator => C-v C-_
in emacs I think you can use C-q in place of C-v
Re:How to Analyze Every Reddit Submission and Comment, in Se... by spilk on Saturday October 03, 2015 @01:31PM (#10324611)
Why use a character like tab, which can also appear in common text, when there are control characters designed exactly for this purpose? ASCII 0x1C - 0x1F are there specifically for machine parsing of tabular data.
Re:How to Analyze Every Reddit Submission and Comment, in Se... by TorKlingberg on Saturday October 03, 2015 @01:34PM (#10324621)
If you use control characters, it is not plain text any more. It's hard to edit with a text editor.

Tabs have a similar problem: They look like spaces in a simple text editor like notepad.

Re:How to Analyze Every Reddit Submission and Comment, in Se... by jsprogrammer on Saturday October 03, 2015 @02:00PM (#10324737)
This just seems like a failing of the text editor.

But, if you can't input the character...you can't input the character.

Re:How to Analyze Every Reddit Submission and Comment, in Se... by twic on Saturday October 03, 2015 @01:51PM (#10324694)
Because you immediately run into some madman who wants to separate the columns with four spaces instead.
Re:How to Analyze Every Reddit Submission and Comment, in Se... by MichaelBurge on Saturday October 03, 2015 @05:16PM (#10325414)
The company I work at uses the pipe character('|') everywhere. It's fairly painless, and you can edit the files using standard text editors. It's also pretty easy for clients to provide or consume pipes. CSVs are terrible - people always have trouble providing or ingesting them with the correct quoting: probably 50% of the time it's suggested there is strong resistance to the idea of using CSV quoting. TSVs are okay - you can copy-paste from Excel into your terminal so it's got that going for it.

There's been one time where a client provided a couple hundred gigabytes of data where all the reasonable characters one might use were used in the fields themselves, including their own separator character(the comma). So I made up some rules for guessing which commas were delimiters and which were part of a field value, and stored it using the ASCII control character as a delimiter. The only other use of this character at my company are in jokes, like "We should ask the client to provide or ingest files separated using the ASCII control codes" which always gets a laugh.

Re:How to Analyze Every Reddit Submission and Comment, in Se... by ised on Saturday October 03, 2015 @11:07PM (#10326265)
"Documents are littered with commas."

It's trivial to change all those commas to something else before making the CSV file and importing into the database.

They can then be converted back to commas by processing the query result.

This type of conversion before storage is routinely done with other characters, such as newlines, quotes, etc. For example, look at the JSON for the 10mHNComments data dump.

Personally, from a readability standpoint, tabs drive me nuts. I am glad TSV is not the default.

Re:How to Analyze Every Reddit Submission and Comment, in Se... by stevepike on Saturday October 03, 2015 @07:33PM (#10325838)
If you haven't tried it, check out the csvkit tools: https://csvkit.readthedocs.org/en/0.9.1/. `csvlook` and `csvcut` are awesome.

I'm also a huge fan of Ruby's `csv` package in the standard library, particularly http://ruby-doc.org/stdlib-1.9.2/libdoc/csv/rdoc/CSV.html#me....

All that only works for properly quoted CSV though... for companies who can't generate quoted csv files pipes or tabs are the unfortunate way to go.

Re:How to Analyze Every Reddit Submission and Comment, in Se... by d0mine on Saturday October 03, 2015 @10:49PM (#10326227)
To get tabs instead of commas:

  #!/usr/bin/env python
  import csv
  import sys
  
  writer = csv.writer(sys.stdout, delimiter='\t')
  writer.writerows(csv.reader(sys.stdin))
Re:How to Analyze Every Reddit Submission and Comment, in Se... by InclinedPlane on Sunday October 04, 2015 @01:41AM (#10326616)
csv is a garbage format but at least it's a standard, and one with a lot of tool support, and that can handle embedded commas in data if processed correctly. The idea that tab separated data is a superior format is, frankly, absurd. I could understand a call for, say, json or even xml, but an ad hoc standardless format which has the solitary advantage of being incrementally easier to parse with awk? No thanks.
Re:How to Analyze Every Reddit Submission and Comment, in Se... by techbio on Saturday October 03, 2015 @11:30PM (#10326330)
NO CONSISTENT DELINEATORS STOP SEND ESCAPE CHARACTERS FULL STOP
Re:How to Analyze Every Reddit Submission and Comment, in Se... by bane on Saturday October 03, 2015 @04:04PM (#10325153)
Use tildes. Tilde Separated Values are relatively robust and nobody uses tildes by themselves for anything I've ever seen. Most tools that let you set a delimiter will accept tildes also.
Re:How to Analyze Every Reddit Submission and Comment, in Se... by icebraining on Saturday October 03, 2015 @04:18PM (#10325196)
nobody uses tildes by themselves for anything I've ever seen

Abbreviated Unix paths? ~/.bashrc

Approximated values? ~30º

Re:How to Analyze Every Reddit Submission and Comment, in Se... by ycitera on Saturday October 03, 2015 @07:07PM (#10325754)
Why use TSV when you can use an sqlite3 file?
Re:How to Analyze Every Reddit Submission and Comment, in Se... by Nicholas_C on Saturday October 03, 2015 @10:44PM (#10326215)
I can't open a sqlite3 file easily in Excel for easy data manipulation, visualization, and sharing.
Re:How to Analyze Every Reddit Submission and Comment, in Se... by walterstucco on Saturday October 03, 2015 @03:01PM (#10324968)
Tab? You mean two spaces right? :)
Re:How to Analyze Every Reddit Submission and Comment, in Se... by dilap on Saturday October 03, 2015 @03:22PM (#10325032)
i agree, but sadly programs like excel tend to do better w/ commas. it's sad.
Re:How to Analyze Every Reddit Submission and Comment, in Se... by nullwagon on Saturday October 03, 2015 @03:10PM (#10324998)
awk -F","

Problem solved.

Re:How to Analyze Every Reddit Submission and Comment, in Se... by z92 on Saturday October 03, 2015 @03:46PM (#10325095)
Not when the data is like this.

  "Richard, Martin", "23 NS, North Coast, NY"
Comma frequently occurs inside texts, and then awk fails.
Re:How to Analyze Every Reddit Submission and Comment, in Se... by ferrari8608 on Saturday October 03, 2015 @05:57PM (#10325539)
awk -F'", "'

That's apostrophe, quote, comma, space, end quote, apostrophe.

Re:How to Analyze Every Reddit Submission and Comment, in Se... by Rangi42 on Saturday October 03, 2015 @07:37PM (#10325848)
Which still fails if the values contain escaped quotes:

    Name, Age, Address
    "James aka ""Jim"", ""licensed"" attorney", 42, "New York"
That's three values:

    James aka "Jim", "licensed" attorney
    42
    New York
And there are other possible irregularities: zero or N spaces after the comma separators; unquoted values when they're not needed; backslash-escaped special characters; escaping newlines.
Re:How to Analyze Every Reddit Submission and Comment, in Se... by Rotten194 on Saturday October 03, 2015 @06:17PM (#10325599)
What if not all columns are quoted? A lot of the time only the columns that need quoting are quoted and the others are bare.
Re:How to Analyze Every Reddit Submission and Comment, in Se... by z92 on Saturday October 03, 2015 @07:24PM (#10325808)
Nice solution.

Will not work were numeric fields are not quoted.

But nice solution, nevertheless.