computing
  • 27

Batch to find text & insert new line of text

  • 27

I need to search all the .cs files in a directory
for the word “Members”, and then insert a new
line with text after it, say “Test”. For example:

Current file has:

Members

After the insert:

Members
Test

I edited the solution here:
https://computing.net/answers/programming/batch-to-find-text-add-new-line-of-text/21255.html, to my problem below:

@echo off > newfile & setLocal enableDELAYedeXpansion

FOR /R C:tara %%a IN (*.cs) DO (
for /f “tokens=1* delims= ” %%i in (%%a) do (
>> newfile echo.%%i %%j
if “%%i” equ “Members” >> newfile echo Test
)
move /y newfile “%%a”
)

However, it does not change anything in the
file (only 1 file currently in that directory). Any tips?

Thanks!

Share