From: Robert Klemme Date: 2010-10-15T22:06:09+09:00 Subject: Re: How do i split a file by newline 2010/10/15 Une Bévue : > Amit Tomar wrote: > >> path="E:/expr/amit.txt" >> File.open(path).each do |i| >> k=i.split("\n" ) >> >> puts  "#{k[0]}" >> end >> >> i should get amit only but am getting >> amit >> sumit >> >> how do i make them split from newline?? > > no need to split("\n") because it's allready done : > #! /opt/local/bin/ruby1.9 > # encoding: utf-8 > k=[] > File.open("amit.txt").each {|l| k< puts k[0] Even simpler k = File.readlines "amit.txt" # different separator # k = File.readlines "amit.txt", "\t" Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/