#!/usr/bin/env lua -- like plain grep, but first arg is not the needle, but a file containing a list of needles function lines(fname) local lst = {} local f = io.open(fname) for line in f:lines() do table.insert(lst, line) end return lst end if select('#', ...) ~= 2 then print("syntax: multigrep needles haystack") return end local needles = lines(select(1, ...)) local haystack = lines(select(2, ...)) table.sort(needles) table.sort(haystack) local pos = 1 local found = false for i, n in ipairs(needles) do for i, h in ipairs(haystack) do local f = h:find(n, 1, true) if f then print(h) end found = found or f end end os.exit(found and 0 or 1)