vote up 10 vote down star
6

Does anyone know of a simple tool that will open up a CSV file and let you do basic, SQLesque queries on it? Like a graphical tool of sorts, one that is easy to use.

I know I could write a small script to do an import of the CSV into a SQLite database, but since I imagine someone else thought of this before me, I just wanted to inquire if one existed. What's prompting this question is I am getting frustrated with Excel's limited filtering capabilities.

Perhaps some other data visualization manipulation tool would provide similar functionality.

Free or OSS is preferred, but I'm open to any suggestions.

EDIT:

I really would prefer some clear tutorials on how to do the below instead of just "make your sheet an ODBC entry" or "write programs using ODBC files", or more ideas on apps to use. Note: I cannot use MS Access.

Yet another EDIT:

I'm still open for solutions using SQLite. My platform is a semi-ancient Win2k laptop, with a P4 on it. It's quite slow, so a resource-light solution is ideal and would likely get the win.

flag

57% accept rate
Just to be sure: you're still open for solutions using SQLite? (Like using the .separator and .import commands?) And what platform are you on? – Arjan van Bentem Jul 19 at 21:30
Just out of curiosity: Why can't you use MS Access? – Ludwig Weinzierl Jul 19 at 22:48
@ Arjan - I'm still open for solutions using SQLite. My platform is a semi-ancient Win2k lappy, with a P4 on it. It's quite slow, so a resource-light solution is ideal and would likely get the win. – sheepsimulator Jul 20 at 13:26
1  
@ fretje - You must not have any experience with SQLite. 1MB total in source code. It's used on cellphones. The Win32 executable (engine and all) is 300KB. – sheepsimulator Jul 20 at 20:07
1  
@sheepsimulator: I know it's light, but my point still stands... ODBC access to text files is basically incorporated in the OS, while with SQLite you still have to install something first and import the csv file into a database. Installing nothing is still less than installing something very small, isn't it? – fretje Jul 21 at 2:12
show 1 more comment

7 Answers

vote up 2 vote down check

Have you tried LogParser?

Log parser is a powerful, versatile tool that provides universal query access to text-based data such as log files, XML files and CSV files, as well as key data sources on the Windows® operating system such as the Event Log, the Registry, the file system, and Active Directory®. You tell Log Parser what information you need and how you want it processed. The results of your query can be custom-formatted in text based output, or they can be persisted to more specialty targets like SQL, SYSLOG, or a chart.

Most software is designed to accomplish a limited number of specific tasks. Log Parser is different... the number of ways it can be used is limited only by the needs and imagination of the user. The world is your database with Log Parser.

A tutorial (and a another one) on using the SQL like query language with CSV files I found using google.

Example Query:

logparser -i:CSV "SELECT TOP 10 Time, Count INTO c:\logparser\test\Chart.GIF 
FROM c:\logparser\test\log.csv ORDER by Time DESC" -charttype:bar3d
link|flag
Forum support and many of your questions will be answered at forums.iis.net/default.aspx?GroupID=51 which is the official logparser forum – Pacifika Jul 22 at 9:44
1  
More examples at codinghorror.com/blog/archives/000369.html Nice; too bad it's Windows only. – Arjan van Bentem Jul 22 at 14:37
vote up 22 vote down

I think OpenOffice.org Database can do what you want. It works like this.

  1. Start Open Office.org Database, it shows the "Database Wizard"

  2. Select "Connect to an existing database: Text"

  3. Specify path to text files as well as details like separator character etc.

  4. Create and execute Queries

If you have ever worked with Microsoft Access you will find the GUI familiar.


If you can do without a GUI there are always the traditional UNIX commands. I use them a lot to do simple queries to (small) CSV files. Here is how it works:

clause      operation   command
-------------------------------
from             join     `join`
where     restriction     `grep`
order by           --     `sort`
group by  restriction      `awk`
having    restriction     `grep`
select     projection      `cut`
distinct  restriction     `uniq`
limit     restriction     `head`
offset    restriction     `tail`
link|flag
Wow, great answer! +1 – theycallmemorty Jul 20 at 13:48
This looks like just the trick. I'll see if I can OO Base onto this aging lappy. – sheepsimulator Jul 20 at 19:40
+1. Cool! Didn't bother to explore OO. Always thought MS O had the edge! – Swanand Jul 22 at 5:43
sick! how is performance for large files. I'm in bioinformatics and have huge tab-delimited junk – 1alstew1 Jul 24 at 23:31
@1alstew1: For large files I'd stay away from both methods and use a real database. Also be sure to use the batch import (LOAD) to get the data into you database, it's much faster than INSERT. – Ludwig Weinzierl Jul 26 at 8:32
show 2 more comments
vote up 10 vote down

You can use ODBC to query text files:

Accessing Text Files using ODBC Data Provider

Note that you don't need MS Access for this to work, the tutorial in the above link just uses MS Access to create the text file, but as you already have a text file, scroll down halfway, and start the tutorial where you see the title Accessing a Text File.

Update: I created a DSN on a .csv file myself to be able to create this step by step tutorial... here it comes:

  • Make sure your .csv file is in its own directory without anything else.
  • Open the "ODBC Data Source Administrator" (start - control panel - administrative tools - Data Sources (ODBC)).
  • Go to the File DSN tab and click on "Add...".
  • Choose "Microsoft Text Driver (*.txt, *.csv) from the list and click "Next >".
  • Give a name for your file data source (e.g. "test") and click "Next >".
  • Click "Finish" (After this, a dialog will appear where the "Data source name" and "Description" fields are indeed greyed out. This is normal. No worries.
  • Uncheck the "Use Current Directory" checkbox. The "Select Directory" button will be enabled.
  • Click the "Select Directory" button and nagivate to the folder in which you placed your .csv file in the first step.
  • Click on the "Options>>" button.
  • Click on the "Define Format..." button.
  • In the left "Tables" list, select your .csv file and click on the "Guess" button. (This will analyse your csv file and create an appropriate field for each column in your .csv file.)
  • Go through the generated columns (F1,F2,...) in the right list, give them meaningful names and set the appropriate data type (sometimes the guessing is not always right).
  • Once everything is set up right, click "OK" (2 times).

At this point you should have a file DSN with which you can access your .csv file through ODBC. If you inspect your folder where the .csv file is placed, you'll see a schema.ini file, which contains the config you just created. When you have multiple .csv files, each one corresponds with a table and each table will have a [filename.csv] block in the schema.ini file in which the different columns are defined... You can also create/change that schema.ini file directly in a text editor in stead of using the GUI described above.

As for your extra question "how to connect to this ODBC provider using a query tool":
I have a tool which I wrote myself long time ago which is not eligible for publication. But a quick Google search came up with odbc-view, a freeware tool which does what you want.
I downloaded and installed the tool.
After starting the tool:

  • Click on "DataSource...".
  • Select your File Data Source which you created previously (e.g. "test").
  • In the query pane type "select * from [filename.csv]".
  • Click "Execute".

You should see the contents of your .csv file in the lower pane now.
Hope this helps... Let me know how you do or if you need further assistance.

link|flag
@ fretje - I know I don't need MS Access for this to work, I tried it myself. I ran into two problems with this: 1. I want to have a GUI, or a CLI utility that I can use to query the CSV-DB with when I am done. The tutorial you've cited above lists none of that, it assumes you want to access this ODBC database by writing a .NET app. 2. With the PC I would use this solution on, I don't think my ODBC setup is sufficient to follow this solution. I wasn't able to name my DSN at ODBC data provider creation time, the box was greyed out. Maybe a system setup problem. – sheepsimulator Jul 20 at 0:11
@ fretje - if you can explain how to connect to this ODBC provider using a query tool, that would be nice; I don't know how to do that. Was kinda looking for a catch-all answer. – sheepsimulator Jul 20 at 0:13
vote up 6 vote down

I like using R to access csv files in a fast way. While the language isn't directly SQL you can do all those things with simple commands in R. R also provides you with the ability to make nice graphs and a lot of other power.

link|flag
vote up 4 vote down

You can always read the file into Excel and use Excel as your data source via ODBC and run queries against it.

link|flag
I can? This sounds like black magick. Can you find a link for a tutorial? – sheepsimulator Jul 17 at 15:05
2  
@sheepsimulator: Excel just opens csv files... once you have an excel file, you can query it with ODBC just like you can query text files (see my answer below). – fretje Jul 17 at 15:12
vote up 2 vote down

I found a small, non-graphical app that does this: csvsql.

Documentation is here.

link|flag
This is EXACTLY the type of app I am looking for, although it would be nice if it had a GUI. Sadly, I really don't have a good way right now to compile it for the Win2k box. Will get back to you. Also, the author didn't use automake or anything nice like that so getting to compile will require some jiggerypokery. – sheepsimulator Jul 20 at 19:34
It was very hard to find and it was the only thing I could find close to what you described. Perhaps an idea for someone to write an application that can import textfiles and run SQL-queries on them using, for example, SQL Lite? – Stefan Thyberg Jul 20 at 19:47
sqlite3 (the command-line application that reads SQLite databases) has built-in support to import files -- see its .separator and .import commands at sqlite.org/sqlite.html – Arjan van Bentem Jul 21 at 8:48
1  
Yes, I saw it mentioned several times in the answers but I was thinking more of a full-fledged notepad-like application with a query window. – Stefan Thyberg Jul 21 at 11:44
vote up 1 vote down

A tool that I've found that, I think, may make this easier in the future is Resolver One.

It's a spreadsheet that generates Python code that is easily modifyable. For those that are developers, and occasionally need to "step down" to solve problems in spreadsheets, this seems like an intuitive way to solve spreadsheet-esque problems in a language they are familiar with.

And it gives me an excuse to use Python. Python makes me happy.

link|flag

Your Answer

Get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.