使用批处理文件命令替换字符串

时间:2016-08-22 12:11:58

标签: batch-file cmd

我有许多名为“12739-5468768.xml”的文件,它们的共同点是“12739”,在这些文件中我想用“AND”替换每个&和每个{{没有任何东西。我尝试了很多命令和python命令,但它似乎不能在我的电脑上运行。

</

3 个答案:

答案 0 :(得分:1)

单个文件的解决方案
这也处理;,文件内容中以@echo off setlocal call :replaceFile "12739-5468768.xml" exit /b :replaceFile set "search=&" set "replace= AND " set "textfile=%~1" set "newfile=%~1.replaced" setlocal DisableDelayedExpansion ( for /f "usebackq delims=" %%i in (`findstr /N "^" "%textfile%"`) do ( set "line=%%i" setlocal EnableDelayedExpansion set "line=!line:*:=!" if defined line ( set "line=!line:%search%=%replace%!" set "line=!line:</=!" ) (echo(!line!) endlocal ) ) > "%newfile%" endlocal exit /b 开头的空行和行。

@angular/common

答案 1 :(得分:0)

你需要逃避&amp; &符号使用^字符。

@echo off
setlocal 
setlocal enabledelayedexpansion 
set "search=^&" 
set "replace= AND " 
set "textfile=12739*" 
set "newfile=Output.txt" 
(
  for /f "delims=" %%i in (%textfile%) do ( 
    set "line=%%i" 
    set "line=!line:%search%=%replace%!" 
    echo(!line!
  )
) > "%newfile%" 
del %textfile% 
rename %newfile% %textfile% 
endlocal

答案 2 :(得分:0)

下载名为“FART”的内容 然后将其包含在批处理文件夹中,然后使用此代码执行操作

// imports...
@NgModule({
  declarations: [
    AppComponent,
    NavbarComponent, 
    SidebarComponent, 
    FooterComponent
  ],
  imports: [
    BrowserModule,
    CommonModule,
    FormsModule
  ],
  providers: [
               //MyService, MyOtherService
             ],
  entryComponents: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule {}