all occurences of each line from a file in another file for each line in the first file This is a code golf problem: Say you have two files, one file s and one  file h. The problem is that for each line l of s you should produce a list that contains all lines of h that contain l. By "contain" I mean a substring, so, for example the line "foobar12baz" contains either foo, bar, foobar, 12, 1 or baz, etc...

You may use any programming language or any program to accomplish this in the least number of characters possible. Instead of a list you may print an array, or other sequence type structure.

Here is some Haskell I wrote that does it in 103 characters, and assumes you have the following modules imported

Data.List

Control.Monad

Control.Applicative

let f = (&lt;$&gt;) lines . readFile in (\(a,b)-&gt; [[d|d&lt;-b, isInfixOf c d]|c&lt;-a]) &lt;$&gt; liftM2 (,) (f "s") (f "h")


Example files:

"h"

asdf1
asd2asdf
s3adsf


"s"

1
2
3


Output:

[["asdf1"],["asd2asdf"],["s3adsf"]]
just grep is enough...

grep -Ff s h