I got 2 files: one has an index of 100 values the other one contains a lot of information I would like to extract information only from my index file. For example:
File1.txt
-name1
-name2
-name3
File2.txt:
Read id: name1
sometext
sometext
Complete
Read id: name8 (not index)
sometext
sometext
Complete
Read id: name2
sometext
sometext
Complete
So i would like to have as a print an output like this
Result:
Read id: name1
sometext
sometext
Complete
Read id: name2
sometext
sometext
Complete
So my code was:
f=open("file1.txt").readlines()
v=[]
for line in f v.push(line[0..-2]) end
reg = Regexp.new(v.join(""))
printing = false
File.open("file2.txt").each_line do |line|
printing > = true if line =~ /reg/puts line if printing
printing = false if line =~ /Complete/
end
But the each_line do can't read my /reg/.. But if i insert /name1/ instead i got the output that i would like to have.. What can i do? Thank you for help