I have a number of text files, need to extract the first instance of some single lines, some consecutive lines and some text between lines:
Document 1
Title of the document
(TOD)Release 3
Version 2Authors
Thomas E. Thomas, John L. John,
Fred A. Fred, Sandra K. SandraCompany A Address
More Authors
Page 3
From this example I need "Title of the Document (TOD)", 3, 2, and all the text between Authors and Page 3, not inclusive. I'm slowly learning so I have some code snippets, but they don't go far enough. I can get a match but need the first instance, and the instance and next line:
File.open("sample.txt").each do |line|
if line[/Document/]
puts line
I've tried to get intervening text but it's not quite right:
File.open("sample.txt").each do |line|
while gets
print if [/Authors/../Page/]
end
If you feel this is too much help to ask for I'd appreciate hints/pointers.
casestatement to decide what to look for and what to do with what you find, and to change the state variable to a new value (probably a symbol) when it sees something else.