How do i split a file by newline

Hi all,
           I would like to know how do i split a file by newline ,am
able to do it tab space like

path="E:/expr/amit.txt"
File.open(path).each do |i|
k=i.split("\t" )

puts "#{k[0]}"
end

o/p: amit

and this is content of my file(amit.txt)

amit sumit

now i changed content of file like

amit
sumit

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??

···

--
Posted via http://www.ruby-forum.com/.

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<<l }
puts k[0]

here i get amit, the first line.

···

Amit Tomar <amittomer25@yahoo.com> 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??

--
  « La bouse de la vache est plus utile que les dogmes :
    on peut en faire de l'engrais. »
    (Mao Tsé-Toung / 1896-1976)

=?ISO-8859-1?Q?Une_B=E9vue?= wrote in post #950421:

···

Amit Tomar <amittomer25@yahoo.com> wrote:

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<<l }
puts k[0]

here i get amit, the first line.

Thanks frnd
but why split("\n") is not working for me

--
Posted via http://www.ruby-forum.com/\.

Even simpler

k = File.readlines "amit.txt"
# different separator
# k = File.readlines "amit.txt", "\t"

Cheers

robert

···

2010/10/15 Une Bévue <unbewusst.sein@fai.invalid>:

Amit Tomar <amittomer25@yahoo.com> 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<<l }
puts k[0]

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

i think because the :
File.open("amit.txt").each {|l| k<<l }
allready split the content of the file by line, then, no more \n ?
the ".each" here would means each line...

···

Amit Tomar <amittomer25@yahoo.com> wrote:

but why split("\n") is not working for me

--
  « La bouse de la vache est plus utile que les dogmes :
    on peut en faire de l'engrais. »
    (Mao Tsé-Toung / 1896-1976)