I have a BAT file that parses out the header of a CSV file and replaces spaces with underscores, then merges a series of CSV files here. The problem is, my header file is very long and is being truncated at 1024 characters. Does anyone have a suggestion? I’m hoping to not have to go to PowerShell or anything beyond basic batch programming if possible.
The only issue is with the headers.
@ECHO OFF
set Outputfolder=c:\Test
REM Get the header string out of one of the files
for %%I in (%outputFolder%\*_stats.csv) do set /p HeaderString=< %%I
REM replace the spaces in that header string with underscores
SET HeaderString=%HeaderString: =_%
REM write that header as the first line of the output file
echo.%HeaderString%>%outputFolder%\all_stats_merged.csv
REM append the non-header lines from all the files
>>%outputFolder%\all_stats_merged.csv (
for %%I in (%outputFolder%\*_stats.csv) do more +1 "%%I"
)