From: guillaume.marcais@... Date: 2006-07-11T08:05:11+09:00 Subject: Re: Write to specified line number of file I think you misunderstand what IO#lineno and IO#lineno= do. The first one returns the number of lines read from the IO stream so far (probably only works if doing line oriented io, i.e. with gets or each), and IIO#lineno= set the base number to start from. Setting lineno does NOT change the position in the stream, it just change what the current counter is: echo "toto" | ruby -e 'p $stdin.lineno; $stdin.lineno = 100; p $stdin.lineno; p $stdin.gets; p $stdin.lineno' 0 100 "toto\n" 101 The easiest is to swallow the file with IO#readlines, sort them at random with Array#sort_by and write them out. In a one liner: ruby -e '$stdout.print($stdin.readlines.sort_by { rand })' < file_to_scramble If the file is really to big to swallow, it can become more complicated. But there is no need to get there in most cases. Hope this help, Guillaume. Aditya Rajgarhia wrote: > Thanks for the reply. That'll work. Ofcourse, using excel is the > straightforward way but I need to do it in Ruby. > > I still think there must be a simple way to move to a specified line in > a file. I could write a function which does that by checking for "\n" at > the end of each line, and will do that unless someone can suggest an > easier method soon. > > > -- > Posted via http://www.ruby-forum.com/.