11 Sept 2013

Delete the first lines from a text file using the command line

Introduction
I often use CSV (Comma Separated Values) files that unfortunately have title text on the first three rows - I don't need this. I just need the header row which always starts at row four. In Excel of course I can just delete the unwanted rows but what if I want to do this from the command line? It might be useful if I would like to automated working with CSV files.


Instructions
Open a command line window (CMD).
Type the following command:
MORE /E +3 original.csv > new.csv  [Enter]

The original.csv has three first lines that I want to delete.
The new.csv does not have the first three lines.


Explanation
The +3 parameter means that it will delete the first three lines of text from the file. You can change this to however many lines (rows) you want to delete. The 'original.csv' is your original source file with the lines that need to be deleted. The > means to output to a new file called new.csv. Of course you can use different file names, the names I've used are just examples.