From: Robert Klemme Date: 2007-04-27T18:15:04+09:00 Subject: Re: Output A File w/ Line Numbers? On 27.04.2007 08:39, John Joyce wrote: > I'd like to read a file and output its contents (just to terminal is > fine for simplicity) with line numbers. > Is there a Ruby library method that handles this like unix cat? > Of course we can write a looping one-liner, but it seems to me this > function must already exist. 11:09:44 [~]: ruby -ne 'print $., " ",$_' foo.txt 1 aaa 2 bbbb 11:09:58 [~]: cat foo.txt aaa bbbb 11:10:01 [~]: cat -n foo.txt 1 aaa 2 bbbb 11:10:04 [~]: If you want it more integrated in a script: 11:11:00 [~]: ruby -e 'ARGF.each {|line| print ARGF.lineno, " ", line}' foo.txt 1 aaa 2 bbbb 11:11:03 [~]: This also works with arbitrary IO's. Kind regards robert