From: Rick DeNatale Date: 2009-03-05T02:33:24+09:00 Subject: Re: implement "paste" using ruby --00163630ee1b9d87fc04644e7750 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Tue, Mar 3, 2009 at 11:28 PM, Oliver wrote: > hi, all > > I have a programming question: in the *NIX world, there is a small > utility named "paste", that can combine several files together by > columns. For example: > > file "x.dat"'s content is: > 1 > 2 > 3 > ... > > file "y.dat"'s content is: > a > b > c > ... > > then "paste x.dat y.dat > z.dat" will generate z.dat as: > 1 a > 2 b > 3 c > ... > > #!/usr/bin/env ruby -wKU files = ARGV.map { |fname| File.open(fname) } while (lines = files.map {|file| file.gets}).any? {|line| line} puts lines.map {|line| line.to_s.chomp}.join("\t") end -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale --00163630ee1b9d87fc04644e7750--