直接上代码
#!/usr/bin/env ruby #encoding: utf-8 filename = ARGV[0] file = File.open(filename) =begin 逐列打印 =end file.each_line do |line| myline = line.chomp! ary = myline.readlines puts ary[1] end file.close
用each_line逐行遍历,然后用readlines将行内容变为数组,然后取出数组中的元素。
注:chomp!用于删除换行符
时间: 2024-12-10 20:35:51