0

Windows でバッチを使用してファイルから複数行の文字列を削除しようとしています。私のバッチコードは、ファイルに文字列を配置するなど、いくつかの奇妙なことを行っていECHO is off.ます。

編集:すべてのコード
を使用して、ファイルから複数行の文字列を削除するコードを取得するにはどうすればよいですか?

@echo off &setlocal enabledelayedexpansion

Rem Read file and store all contents in string
Set replace=
Set target=
Set infile=usermenuTest1.4d
Rem %~1
Set outfile=usermenuTest2.4d
Rem %~2

for /f "delims=" %%i in (%infile%) do set "target=!target! %%i"
echo %target%

Rem Remove the target string from myOtherFile.txt: this code is from http://stackoverflow.com/questions/5273937/how-to-replace-substrings-in-windows-batch-file
@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%"

置き換えたい複数行の文字列の例:

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

Menu "" {
   // Button "CAD" {
   //   Walk_Right "CAD"    
   //   }
    Button "Design" {
      Walk_Right "Design"    
      }
    Button "Services" {
      Walk_Right "Services"        
      }
    Button "Strings" {
      Walk_Right "Strings"        
      }
    Button "Survey" {
      Walk_Right "Survey"        
      }
    Button "Utilities" {
            Walk_Right "Utilities"        
      }
    Button "Zoom" {
      Walk_Right "Zoom"        
      }        
  }
4

1 に答える 1

0

これを試して:

@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%"
于 2013-04-30T04:34:40.780 に答える