From: Sebastian Hungerecker Date: 2007-07-11T21:11:09+09:00 Subject: Re: if / else, how to include next line Marc Hoeppner wrote: > Ideally,the program would read this keyword-file, store the information > in a variable (an array, I guess) and then use this array to identify > the entries in the "main" file and puts them into stdout. Something like this should work: # Store the contents of keywords.txt in an array: keywords=File.readlines("keywords.txt") # Read main.txt, then create an array of arrays where the first element # contains the KOG-line and the second contains the text up to the next # KOG-line (or the end of the file). Then convert the whole thing into a hash: hash=Hash[*File.read("main.txt").scan(/(KOG\d+\n)(.+?)(?=KOG|\Z)/m).flatten] # For each keyword puts the corresponding text from the hash: keywords.each { |keyword| puts keyword, hash[keyword] } HTH -- NP: Anathema - Pitiless Ist so, weil ist so Bleibt so, weil war so