I have a file I source from an SAP system, that I need to massage, and then import to a target system.
One of the steps requires me to change the header.
I need to change:
Code: Select all
,Source,Short_Code,Desc,Code+Desc,Comp_code,Entity,Local_Currency,Management_Unit,Location,Country,Organizational_Parent,Functional_Parent
to:
Element,Source,Short_Code,Desc,Code+Desc,Comp_code,Entity,Local_Currency,Management_Unit,Location,Country,Organizational_Parent,Functional_Parent
Essentially, I'm just adding a name for the first column.
The code I'm using to perform the find and replace is as follows:
Code: Select all
setlocal enableextensions disabledelayedexpansion
set SEARCH=,Source,Short_Code,Desc,Code+Desc,Comp_code,Entity,Local_Currency,Management_Unit,Location,Country,Organizational_Parent,Functional_Parent
set REPLACE=Element,Source,Short_Code,Desc,Code+Desc,Comp_code,Entity,Local_Currency,Management_Unit,Location,Country,Organizational_Parent,Functional_Parent
set FILE_PATH=%LOCALEXPORTPATH%
set "FN=%~n0.csv"
set "FILE=%FILE_PATH%%FN%"
for /f "delims=" %%i in ('type "%FILE%" ^& break ^> "%FILE%" ') do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:%SEARCH%=%REPLACE%!"
>>"%FILE%" echo !line!
endlocal
)
However, it takes forever since it cycles through the whole file. Is there a way to speed this up or somehow force it only look at line 1?
Thanks!