0

hope you guys can help. i am looking for a batch file to merge all CSV files in a specific folder with an End of Line "LF".

The script below creates an output file with "CRLF" EOL, however my automatic data loader only accepts "LF" EOL.

Also i would like to have one header in the output file.

help would be much appreciated as i have wasted enough time finding a solution.

this is what i tried below.

 @ECHO OFF
SET first=y
SET newfile=new.csv
for %%F in (*.csv) do IF NOT %%F==%newfile% (
  if defined first (
    COPY /y "%%F" %newfile% >nul
    set "first="
  ) else (
    FOR /f "skip=1delims=" %%i IN (%%F) DO >> %newfile% ECHO %%i
  )
) 
  • 1
    Welcome as a new user to SO. Please take the [tour] and also read [ASK]. [SO] isn't a free script writing service. Own research and code attempts are expected. [Edit] the question to include **your** code in a [mcve]. Two hints: 1st [line endings](https://stackoverflow.com/questions/40803502/echo-text-with-unix-line-endings-from-a-windows-batch-bat-script) 2nd provided the headers are all the same use [more +1](http://ss64.com/nt/more.html) –  Oct 11 '18 at 10:59
  • Are the input files only `LF` terminated? – Squashman Oct 11 '18 at 16:44
  • The input files are LF. But the output file is CRLF. – Mandip Dhillon Oct 11 '18 at 18:00
  • What about converting CR+LF to LF later by an editor like NotePad++ or something? because in pure batch scripting, creating LF-only files is not quote trivial... – aschipfl Jun 04 '19 at 13:20

1 Answers1

0

I am nearly there, however the second CSV file changes the EOL to CRLF. Here my code below.

@echo off
set "first=Yes"
(for %%a in ("H:\data dumps\folder\combine\*.csv") do (
  if defined first (
    type "%%a"
    set "first="
  ) else (
    more +1 "%%a"
  )
))>"H:\data dumps\folder\combine\test.csv"