From: Karthikeyan Balasubramanian Date: 2009-09-23T18:55:24+09:00 Subject: Mini Parser Hi all, I have a requirement. I have a to read some commands from file and output as another file. For example if the input file is like below: 6 WRITE Today WRITE is UNDO 1 WRITE my UNDO 2 WRITE birthday Output file will be like this. Today is birthday WRITE basically write's string after the command and UNDO will undo N number of line preceding it. Complexity here is last UNDO has to UNDO the previous undo's work. So far I have been able to only come up with the below code: begin file = File.new("abc.txt", "r") while (line = file.gets) line.grep(/WRITE/) { |s| puts s } end file.close rescue => err puts "Exception: #{err}" err end Any help here? -- Posted via http://www.ruby-forum.com/.