SELECT is an SQL interface to text files.
$ SELECT response_code, count(1) FROM access_log WHERE method = "'GET'"
> GROUP BY response_code ORDER BY 2 DESC
response_code | count(1)
200 | 157820
404 | 25138
304 | 17938
301 | 2348
302 | 1486
206 | 673
405 | 16
401 | 15
500 | 8
403 | 1
$ head -1 access_log
pd90b3592.dip.t-dialin.net - - [23/Sep/2007:22:42:04 +0200] "GET / HTTP/1.1" 200
768 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:184.108.40.206) Gecko/20061201 Fir
SELECT currently specificially supports the NCSA extended/combined transfer log format (access_log), and all other text files generically. It is easily extensible to support other text file formats.
SELECT is licensed under the GPL Version 3.
SELECT requires Python and pysqlite2. Python 2.5 includes pysqlite2.
Download and unpack the tarball and copy SELECT to a directory in your $PATH, for example /usr/local/bin:
$ wget http://select.mbertheau.de/files/SELECT-0.1.tar.bz2
$ tar xfj SELECT-0.1.tar.bz2
$ sudo cp SELECT-0.1/SELECT /usr/local/bin
SELECT [fieldlist] FROM file [rest_sql]
fieldlist is a comma separated list of field names or the special keyword all, which is replaced by a star *. file is a file name or - to read from standard input. rest_sql may contain SQL clauses like WHERE, GROUP BY, HAVING, LIMIT, OFFSET and ORDER BY.
How it works
SELECT at first tries to determine a file type a set of regular expressions. If that succeeds, speaking column names are available, and the lines are split into columns according to their semantics. If it didn't, they are named with numbers and split by white space. Then SELECT loads the data into an in-memory SQLite database, executes the query and outputs the results to stdout.