I have a large csv. I want to delete the first line of the file. How is this done? I don't want to copy every line into an array and rewrite them for the previous index and delete the first. There must be a better way. (maybe with fastercsv? how?)
4 Answers
Something like :
source=File::open("source","r")
dest=File::open("dest","w")
source.each_line do |line|
next if f.lineno == 1
dest.write(line)
end
source.close
dest.close
3 Comments
David Unric
Wrong, whole source file is read into memory questioner would like to avoid.
Yoann Le Touche
My bad, I read the question too quickly. Here's a modified version reading the file line by line
Michael Kohl
You are not closing the file handles. Either close them explicitly or use the block form of
File.open.