From: 7stud -- Date: 2012-12-17T10:01:18+09:00 Subject: Re: print - and strip text between tags using Nokogiri Paul Mena wrote in post #1089283: > > # remove blank lines from file > fh = File.open('snippet.txt') > while( !fh.eof) > line = fh.readline.chomp > # remove leading and trailing blanks > line.strip! > # skip empty lines > next if line == '' > # convert tab chars to blanks > line.gsub!(/\t/,' ') > # substitute a single blank for a sequence of blanks > line.squeeze!(' ') > # add code to process line if needed > puts line > end > fh.close > exit(0) > I forgot to mention. There are several ways to read line by line from a file, but your loop is particularly ugly. If you use my favorite: IO.foreach(fname) do |line| line = line.chomp ... .. end The added benefit is that the file is automatically closed when the block exits. -- Posted via http://www.ruby-forum.com/.