title: Simple, fast SQL queries for flat files
body: <p>Does anyone know of any tools to provide simple, fast queries of flat files using a SQL-like declarative query language?  I'd rather not pay the overhead of loading the file into a DB since the input data is typically thrown out almost immediately after the query is run.</p>
  
  <p>Consider the data file, "animals.txt":</p>
  
  <pre><code>dog 15
  cat 20
  dog 10
  cat 30
  dog 5
  cat 40
  </code></pre>
  
  <p>Suppose I want to extract the highest value for each unique animal.  I would like to write something like:</p>
  
  <pre><code>cat animals.txt | foo "select $1, max(convert($2 using decimal)) group by $1"
  </code></pre>
  
  <p>I can get nearly the same result using <code>sort</code>:</p>
  
  <pre><code>cat animals.txt | sort -t " " -k1,1 -k2,2nr
  </code></pre>
  
  <p>And I can always drop into <code>awk</code> from there, but this all feels a bit <code>awk</code>ward (couldn't resist) when a SQL-like language would seem to solve the problem so cleanly.</p>
  
  <p>I've considered writing a wrapper for SQLite that would automatically create a table based on the input data, and I've looked into using Hive in single-processor mode, but I can't help but feel this problem has been solved before.  Am I missing something?  Is this functionality already implemented by another standard tool?</p>
  
  <p>Halp!</p>