I need to replace the first line in a text file. Therefore, I've implemented this piece of code:
Code: Select all
SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
SET FILE_SEARCH="Element","Desc","RM_IO","RM_IO_DESC","RM_Shortcode","PROTOCOL_NO","Source","RM_PFP","RM_PFP_Alias","RM_PFI","RM_PFI_Alias","RM_PFC","RM_PFC_Alias","PF_TherapeuticArea","ALLIANCE_PARTNER","DIRECT_INDIRECT","IP_OWNER"
SET FILE_REPLACE="Hierarchy ^(Code^)","Code Desc","MDM IO","MDM IO Desc","MDM IO Shortcode","MDM Protocal Number","MDM IO Source","PFP","PFP Alias","PFI","PFI Alias","PFC","PFC Alias","TA","ALLIANCE_PARTNER","DIRECT_INDIRECT","IP_OWNER"
SET "FILE_PATH=%LOCALEXPORTPATH%"
SET "FN=%TIGER_NAME%.csv"
SET "FILE=%FILE_PATH%%FN%"
FOR /f "delims=" %%L IN ('TYPE "%FILE%" ^& BREAK ^> "%FILE%" ') DO (
SET "LINE=%%L"
SETLOCAL ENABLEDELAYEDEXPANSION
SET "LINE=!LINE:%FILE_SEARCH%=%FILE_REPLACE%!"
>>"%FILE%" ECHO !LINE!
ENDLOCAL
)
However, I'm exploring the JREPL solution which would be much quicker but I'm having difficulty getting it to work. Where am I going wrong? Thanks!
Code: Select all
@ECHO OFF
CALL _env.cmd
SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
SET NEWLINE="Hierarchy ^(Code^)","Code Desc","MDM IO","MDM IO Desc","MDM IO Shortcode","MDM Protocal Number","MDM IO Source","PFP","PFP Alias","PFI","PFI Alias","PFC","PFC Alias","TA","ALLIANCE_PARTNER","DIRECT_INDIRECT","IP_OWNER"
SET "FILE_PATH=%LOCALEXPORTPATH%"
SET "FN=SAP_to_Order_Reference_Mapping.csv"
SET "FILE=%FILE_PATH%%FN%"
jrepl "^FMOD.*" "%NEWLINE%" /jbegln "skip=(ln!=1)" /f "%FILE%" /o -
pause