开发者

Opening/using a table up in Ruby

开发者 https://www.devze.com 2023-01-07 06:26 出处:网络
I have a simple tab-separated text file that I want Ruby to read every value in the second column and write out a text file with each table value and another number. I was wond开发者_JS百科ering how m

I have a simple tab-separated text file that I want Ruby to read every value in the second column and write out a text file with each table value and another number. I was wond开发者_JS百科ering how might I go about doing this (probably using some kind of loop).

Thanks


File.open("output.txt", "w") do |output_file|
  File.open("input.txt") do |input_file|
    input_file.each_line do |line|
      values = line.split("\t")
      output_file.puts "#{values[1]} anothervalue"
    end
  end
end
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号