@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion

: Creates a local MK from a given MK filename, it expects to be at kernels/mk folder.
: Usage: update_local_mk.bat mk_filename kernels_folder_path mk_local_filename

Set "search=.."
Set "replace=%2"
Set "File=%1"
Set "FileOut=%3"

For /F "Tokens=1*Delims=]" %%A In ('Find /V /N ""^<"%File%"^&Break^>"%FileOut%"'
)Do (Set "line=%%B"
    SetLocal EnableDelayedExpansion
    (If Not "%%B"=="" (Echo(!line:%search%=%replace%!)Else Echo()>>"%FileOut%"
    EndLocal)