I’m using the following piece of code; to change something in a Cmakefile:
for /f %%j in (CMakeLists.txt) do (
if "%%j"=="Extensions_AntTweakBar" (
echo #Extensions_AntTweakBar >> temp.tmp
) else (
if "%%j"=="Extensions_Inspection" (
echo #Extensions_Inspection >> temp.tmp
) else (
if "%%j"=="Extensions_InspectionBar" (
echo #Extensions_InspectionBar >> temp.tmp
) else (
echo %%j >> temp.tmp
)
)
)
)
It seems to work, that is, it does change the selected lines, however, if theres a space on one line, it only gets that line till the space occurs.
Example:
SET( PROJECT_NAME "MyProject")
Only gets the string:
SET(
How am I supposed to get the full string then?
In your code you append a space at each line.
Here you can remove it(works only with %%j), but normally it is better to set the redirection as prefix, like
With a normal variable the postfix variant could fail
Expands to echo hallo2>temp.tmp or echo hallo 2> temp.tmp, so only the stderr would redirected.
The next problem are the keywords ON OFF /?, if your file contains such a word you get unexpected results, because the echo interprets these words.
[EDIT:] To solve this you can use echo(
You can get empty lines (or lines with only whitespaces), you simply need to prefix them.
The toggling of the DelayedExpansion is neccessary to preserve “!” and “^” characters