From: tamouse mailing lists Date: 2013-02-14T14:37:02+09:00 Subject: Re: file size of each item in file list On Wed, Feb 13, 2013 at 4:30 PM, Sloan Ruby wrote: > I am trying to take the contents of a file which contains the results of > a file size search and print those out with ruby. To obtain the file > size of each line in that file. > > #!/usr/bin/ruby > > f = File.open("/tmp/lg_files") > contentsArray=[] # start with an empty array > f.each_line {|line| > a = contentsArray.push line > #b = File.size(a) > puts a > } > > > This results in each line in the file /tmp/lg_files printing. Is this just an partial step to doing something else? Because to do what you originally posted, all that's required is something like this: IO.readlines("/tmp/lg_files").each{|l| l.chomp!; puts "#{l} #{File.size(l)}" }