From: ahoward Date: 2003-06-22T07:44:35+09:00 Subject: Re: reading text line On Sat, 21 Jun 2003, Dan wrote: > i want to read a line of string from a file every other line > > line one > line two > line three > line four > > want it to print > > line one > line three > > -------------------f = File.new("testfile") > f.each {|line| puts "#{f.lineno}: #{line}" } > > > > should i have > #(f.lineno)/2 == true > ...do something > > else...do somethin else? use % /usr/home/howardat > cat odds.rb #!/usr/bin/env ruby cat = IO.popen 'cat', 'w+' cat.write DATA.read cat.close_write # the pertinent bit print if $. % 2 == 0 while cat.gets __END__ zeroth first second third fourth fifth sixth seventh eigth ninth /usr/home/howardat > ruby odds.rb first third fifth seventh ninth -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ara.t.howard@noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 | ~ > ruby -e 'p(%.\x2d\x29..intern)' ====================================