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
···
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 fourwant 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 somethingelse…do somethin else?
–
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)’
====================================