Remove header from multiple csv files using batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
chandu
Posts: 1
Joined: 04 Dec 2016 02:34

Remove header from multiple csv files using batch file

#1 Post by chandu » 04 Dec 2016 03:39

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

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: Remove header from multiple csv files using batch file

#2 Post by SIMMS7400 » 04 Dec 2016 15:32

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
    )
)

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Remove header from multiple csv files using batch file

#3 Post by Squashman » 04 Dec 2016 15:42

Please provide a real world example of your input data and what you want the output to look like.

Post Reply