I have an .sql file and want to replace all lines like this:
VALUES (12,
VALUES (24,
VALUES (9999,
with
VALUES (NULL,
I have tried like this, but the regex does not seem to work and the output does not change
@echo off
setlocal enabledelayedexpansion
set "replacement=VALUES (NULL,"
set "regex=VALUES \(\d+,"
set "output_file=updated_sql_dump.sql"
(for /f "delims=" %%i in ('type "MONITORING-schema.sql" ^| findstr /n "^"') do (
set "line=%%i"
echo !line! | findstr /r /c:"%regex%" >nul && (
echo !line:%search%=%replacement%!
) || (
echo !line:*:=!
)
))
I propose the following:
What it does is generating a dynamic string by replacing the given string with a defined constand string. This dynamic string is now replaced from the given string with the defined replacement string.
The important line is
Output:
this is based on this answer: https://superuser.com/a/807645/1850668