From: David Alan Black Date: 2002-05-06T19:53:17+09:00 Subject: Re: newbie Q: how to strip blank lines from file? Hi -- On Mon, 6 May 2002, Tobias Reif wrote: > David Alan Black wrote: > > > > fout = File.open("snip.out", "w") > > File.open("snip.txt").each do |line| > > fout.print line if /\S/.match(line) > > end > > > I'm not sure, but shouldn't snip.out get closed? Yeah, probably. > Should the following work? > > > open("snip.out", "w") do |out| > open("snip.txt").each do |line| > out.print line unless /^\s+$/.match(line) > end > > end The regex doesn't match a blank line -- you need a * instead of a +. (Or use /\S/, but I seem to be the only fan of that :-) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav