open a given input file open the output file read first line of input (this will be the csv header) look at the size of the output file if output file size is zero, write the csv header to output loop through remaining lines of input file write lines to output when appropriate