直接上代码
#!/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!用于删除换行符
本文出自 “专注Linux 运维” 博客,转载请与作者联系!
原文地址:http://purplegrape.blog.51cto.com/1330104/1884356