Batch Copy

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tatebn
Posts: 1
Joined: 04 May 2009 12:47

Batch Copy

#1 Post by tatebn » 04 May 2009 12:53

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.

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 05 May 2009 09:17

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.

Post Reply