I have a text file, I was wondering anyone have a batch file to add \" to the beninning and \", at the end of each line in a text file?
For example I have
set "f=PATH\FILE.txt"
call :add_str_beginning_end_each_line "BEGIN_LINE--" "--END_LINE" "%f%"
REM : Adds strings at the beginning and end of each line in file
:add_str_beginning_end_each_line
set "str_at_begining=%~1"
set "str_at_end=%~2"
set "input_file=%~3"
set "tmp_file=tmp.ini"
REM : >NUL => copy command is silent
REM : Make a backup
copy /Y "!input_file!" "!input_file!.bak" >NUL
copy /Y "!input_file!" "!tmp_file!" >NUL
del "!input_file!"
REM : Add strings at each line
for /f "delims=" %%a in (!tmp_file!) do (
>>"!input_file!" echo !str_at_begining!%%a!str_at_end!
)
REM : delete backup
del "!tmp_file!"
del "!input_file!.bak"
REM : exiting the function only
EXIT /B 0
You can edit the code :
"!input_file!" echo !str_at_begining!%%a!str_at_end!
By removing !str_at_end! to add str only at the beginning of the line, where %%a is the actual line.