views:

91

answers:

3

I have a very large CSV file and I need to write an app that will parse it but using the >6GB file to test against is painful, is there a simple way to extract the first hundred or two lines without having to load the entire file into memory?

The file resides on a Debian server.

+5  A: 

Did you try the head command?

head -200 inputfile > outputfile
Stephen Darlington
Nice answer I've never heard of head... thanks.
Unkwntech
Use "-n 200" instead of "-200". The latter is deprecated syntax.
David Schmitt
The GNU documentation says it's "obsolete" but I've not seen anyone else declare it deprecated. The Solaris docs, for example, lists both methods but offers no preference.
Stephen Darlington
A: 
  • head -10 file.csv > truncated.csv

    will take the first 10 lines of file.csv and store it in a file named truncated.csv

tehvan
A: 

"The file resides on a Debian server."- this is interesting. This basically means that even if you use 'head', where does head retrieve the data from? The local memory (after the file has been copied) which defeats the purpose.

Amit
Judging by the accepted answer, I think it's fair to assume that the OP mentioned Debian to ensure posters knew the target OS.
David Grant
Weird. Why then was it even mentioned?
Amit
Gave the impression that he was trying to partially pull it from the server..
Amit