Live data from Hacker News

How To Open and Manipulate Large CSV Files On A Mac

alecdibble.com

11–20 of 57 posts

Re: How To Open and Manipulate Large CSV Files On A Mac

#11
post #4

Sublime Text and VSCode work fine with 1GB files in my experience.

I think the article tries to go into further depth beyond what a text editor can do on CSV files (filtering, sorting).

That said, worth mentioning CSV syntax highlighters for text editors. I’ve found rainbow csv quite helpful (https://github.com/mechatroner/sublime_rainbow_csv)

Re: How To Open and Manipulate Large CSV Files On A Mac

#15

No mention of vi or Sqlite? While I'm no vi expert it's a great tool for working with big files when you want to browse around without grep. And Sqlite is similarly ubiquitous and capable of crunching large files.

vi is an editor so it doesn't really solve my requirement of getting spreadsheet-like editing capabilities. SQlite is a good idea, I never thought of that. I will investigate that and add it to the article. Thanks!

SQLite does a great job of importing CSV, and then you're able to use something like "DB Browser for SQLite"[1] to browse the data.

I use something like this to fix up column names and import:

    sed -i '' -e '1 s/ \/ /_/g; 1 s/[() ]/_/g' $csv_file
    sqlite3 $db_file 
[1] https://sqlitebrowser.org/

Re: How To Open and Manipulate Large CSV Files On A Mac

#16
post #15

Earlier quoted context omitted.

vi is an editor so it doesn't really solve my requirement of getting spreadsheet-like editing capabilities. SQlite is a good idea, I never thought of that. I will investigate that and add it to the article. Thanks!

SQLite does a great job of importing CSV, and then you're able to use something like "DB Browser for SQLite"[1] to browse the data. I use something like this to fix up column names and import: sed -i '' -e '1 s/ \/ /_/g; 1 s/[() ]/_/g' $csv_file sqlite3 $db_file [1] https://sqlitebrowser.org/

Amazing, I will definitely try this out. Thank you!

Re: How To Open and Manipulate Large CSV Files On A Mac

#17
I'm always astounded that there doesn't seem to be a decent general purpose CSV editor/viewer application. Excel is atrocious - it's always dog slow, and it mangles any CSV I've ever opened by trying to interpret the data to format it "smartly".

Having to build a table in a database and import the CSV into that feels a bit like hitting a house fly with a sledgehammer, but it's the most effective way I've seen.

Re: How To Open and Manipulate Large CSV Files On A Mac

#18
post #14

You could get interested in: https://github.com/BurntSushi/xsv

Thank you for linking this. It seems to be much more intuitive than awk, especially for his particular purpose. I wish I would have found this a few months ago when I was slicing and dicing lots of data for an extensive system migration project.

Re: How To Open and Manipulate Large CSV Files On A Mac

#19

I'm always astounded that there doesn't seem to be a decent general purpose CSV editor/viewer application. Excel is atrocious - it's always dog slow, and it mangles any CSV I've ever opened by trying to interpret the data to format it "smartly". Having to build a table in a database and import the CSV into that feels a bit like hitting a house fly with a sledgehammer, but it's the most effective way I've seen.

One can convert CSV into JSON (a recipe is e.g. here - https://infiniteundo.com/post/99336704013/convert-csv-to-jso... ) - in streaming fashion - and then use jq ( https://stedolan.github.io/jq/ ) to do what one needs.

Re: How To Open and Manipulate Large CSV Files On A Mac

#20
post #2

Why do you want to do that? Use cat, pipe, grep, awk. Problem solved.

I personally am not a huge fan of awk, I've never built a great mental model around its syntax and it doesn't really solve the problem I was talking about, which is getting a spreadsheet-like editing experience. Thanks for bringing it up, I should definitely add it to the article.

For the quoted spreadsheet-like operations of filtering and rearranging, awk is perfect as a deferred editor. That the kludgy first step of your chosen solution ("First, you must create a CSV file contain only the first 10-20 lines of your large CSV file") isn't just `head very_large_nov_2019.csv > very_large_nov_2019_abridged.csv` seems to further indicate an unfamiliarity with the large set of built-in, battle-tested UNIX tools for dealing with text files.

The first tools I reach for when dealing with CSVs of these and larger magnitudes are less, cut, awk, etc. They also tend to be the last tools I end up needing.

Post reply on HN