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/. >From one newbie to another. Assuming that the file can be read into memory and you want to shuffle the lines around. read in the file and place the lines in an array and use a shuffle method such: def shuffle(ar) stop_line = line_b = ar.size - 1 # by time were here, the lines are a scramble as they going to get stop_line /= 5 stop_line.upto(ar.size - 1) do line_a = rand( line_b ) # exchange first and last line ar[line_a], ar[line_b] = ar[line_b], ar[line_a] line_b -= 1 end return ar end then you write back the lines into a new file or simply overwrite the old file.