Remove Multi-Line String from File

gretty

Honorable
Apr 30, 2013
2
0
10,510
Hello

Is the functionality I describe below possible using Batch Windows Scripting? And if so how I can I edit my code to perform this functionality?

I am attempting to remove a multiline string from a file. The multiline string comes from another file and is read into a Batch variable. I then read the target file and search for this multiline string, if it exists I want to delete it from the target file.

My code below is unable to remove the multiline string from the target file. It can successfully read the input file. Can you help me edit my script to search for and remove a multiline string from a file?

C++:
@echo off &setlocal enabledelayedexpansion
    
    Set replace=
    Set target=
    Set infile=usermenuTest1.4d
    Set outfile=usermenuTest2.4d
    
    Rem Read file and store all contents in string
    for /f "delims=" %%i in (%infile%) do set "target=!target! %%i"
    echo %target%
    
    Rem Remove the target string from outfile
    @echo off & setlocal enabledelayedexpansion
    for /f "tokens=1,* delims=¶" %%A in ( 'type "%outfile%"') do SET "string=%%A"
    SET "modified=!string:%target%=%replace%!"
    (echo(%modified%)>> "%outfile%"
    
    ECHO.
    PAUSE
    ENDLOCAL

Essentially I want my script to remove the following bold text from a file:

// abc

// def

// hij

Menu "User" {
Button "" {
Walk_Right ""
}
}

 
I'm not knowledgeable with Windows batch scripting, but I can write it in Perl.

Perl:
open my $fh1, '<', '<FILENAME1>'   or die('cannot open file for reading');
open my $fh2, '>', '<FILENAME2>'   or die('cannot open file for writing');

LINE: while (my $line = <$fh1>)
{
    chomp($line);
    if ($line =~ /\A\s*\z/  ||  $line =~ /\A\/\//)
    {
        print {$fh2} $line;
    }
}

close $fh1;
close $fh2;
 

gretty

Honorable
Apr 30, 2013
2
0
10,510
Yes I would write this in Python and it would be sooo easy. But not all versions of Windows(if any) have Python installed AFAIK

Is there a Perl interpreter automatically installed on Windows XP and up? I am distributing an installer that would run the script.