#!/usr/bin/lua --[[ mutt_query.lua - find an e-mail address in 'doc/addresses.added' matching arg 1. Copyright 2005 (c) by Peter Stuifzand This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ]]-- --[[ The format of the addresses.added file is: name;email;comment Peter;peter@stuifzand.com;Author of mutt_query Another;noone@noone.unk; Please keep in mind, that this is my first Lua program. I can compile my version using: luac mutt_query.lua More info can be found at http://www.peterstuifzand.nl/mutt.html. Or mail me at: mailto:peter@stuifzand.com. ]]-- require "split" inputfile = os.getenv("HOME") .. "/doc/addresses.added" results = {} for line in io.lines(inputfile) do if string.find(string.lower(line), arg[1]) then t=strsplit(";", line) table.insert(results, {t[2], t[1], t[3]}) end end table.sort(results, function(b,a) return a[1] > b[1] end) print(string.format("%d matches found...", table.getn(results))) for i,item in ipairs(results) do print(table.concat(item, "\t")) end