Page 1 of 1

Batch Copy

Posted: 04 May 2009 12:53
by tatebn
I'm using the copy command to combine several csv files. I was wondering, is there a way to ignore the first line of each file after the first one.

I'm not really familiar with batch programming and have to do this one little thing for work. Something along the lines of if(first file) copy all else {copy all but first line}


Also, what would be the easiest way to go about trimming each line.

Posted: 05 May 2009 09:17
by avery_larry
I would use a utility called split.exe. It'll split your files for you and allow you to recombine them.

Otherwise, in "pure" dos, it's difficult to properly parse files and skip single lines WITHOUT skipping blank lines (not to mention dealing with special characters).

UNTESTED

Code: Select all

set outfile=c:\tmp\file.csv
copy "%~1" %outfile%
shift
for %%A in (%*) do (
   for /f "usebackq skip=1 delims=" %%a in ("%%~A") do echo.%%a>>%outfile%
)

blank lines will just be skipped. Special characters might make it choke (especially the pipe character). If you need blank lines, then you have to use a trick with find /n to pad out the blank lines and then a much more complicated for statement to get rid of the padding.