Remove header from multiple csv files using batch file
Moderator: DosItHelp
Remove header from multiple csv files using batch file
I have two files in a folder file1.csv and file2.csv that contain the data. file1.csv with column names name and sal and file2.csv with the same column names name and sal. required header columns are present in headerfile.csv in the same folder and the column names are ename and esal. My requirement is to replace headers in file1 and file2 with headers from headerfile
Re: Remove header from multiple csv files using batch file
Code: Select all
setlocal enableextensions disabledelayedexpansion
set SEARCH1=name
set REPLACE1=ename
set SEARCH2=sal
set REPLACE2=esal
FOR %%F IN ( file1.txt file2.txt ) DO (
for /f "delims=" %%i in ('type "%%F" ^& break ^> "%%F" ') do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:%SEARCH1%=%REPLACE1%!"
set "line=!line:%SEARCH2%=%REPLACE2%!"
>>"%%F" echo !line!
endlocal
)
)
Re: Remove header from multiple csv files using batch file
Please provide a real world example of your input data and what you want the output to look like.