batch-file - 替换 TXT 文件中的字符串
问题描述
我想替换文本文件中的一行。下面的脚本用于删除该行,但它将该行替换为 true==true。我知道这是由于我的>>"%textFile%" echo(!line:%search%=%!)
设置方式。我希望它只是删除该行,然后我可以回显替换变量,但我在弄清楚如何做到这一点时遇到了问题。
@echo off &setlocal
set "search=xxxxx"
set "replace=yyyyy"
set "search_1=zzzzz"
set "replace_1=aaaaa"
set "textfile=%userprofile%\AppData\....."
for /f "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile%" ') do (
set "line=%%i"
>>"%textFile%" echo(!line:%search%=%!)
>>"%textFile%" echo(%replace%
endlocal
for /f "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile%" ') do (
set "line=%%i"
>>"%textFile%" echo(!line:%search_1%=%!)
>>"%textFile%" echo(%replace_1%
endlocal
)
解决方案
推荐阅读
- sql - 查找所有非常规的单引号
- alignment - 如何在 XSL-FO 中垂直对齐长表的文本底部
- text - 如何将值与 UltraEdit 上的同一列对齐?
- java - 在 Oracle 数据库中存储不同类型数据的最佳体验
- php - Laravel,composer 需要 laravel/ui,移除 laravel/framework v7.25.0
- php - 检索远程用户的 Wikipedia 搜索
- javascript - 如何从 HTML 文件中更改文本
- f# - 使用元组列表定义模式匹配函数时出现 F# 异常错误
- c# - 禁用与当前视图对应的当前按钮wpf c#
- ballerina - 如何处理foreach中的xml?--> 不兼容的类型:预期的 'xml',找到 '(xml|string)'