File.open(path, 'r').each do |line|
row = line.chomp.split('\t')
puts "#{row[0]}"
end
path is the path of file having content like name, age, profession, hobby
I’m expecting output to be name only but I am getting the whole line.
Why is it so?
Your question was not very clear
split("\n")– if you want to split by linessplit– if you want to split by spacesand as I can understand, you do not need chomp, because it removes all the “\n”