我需要使用批处理来检查文件Directory.twml,看它是否包含文件blocked.twml任何文字取代,如果它确实与[锁定]批处理文件中查找文本与其他文本
这里更换是这两个文件的一个例子:
Directory.twml
11:38:38.90 [System] Twml Has joined the chat.
11:38:41.17 [User] Twml says: line one
11:38:42.96 [User] Twml says: line bad two
11:38:46.27 [User] Twml says: line three
11:38:50.16 [User] Twml says: you get the idea here
11:38:52.35 [System] Twml Has logged off.
Blocked.twml
word1
word2
word3
bad
word5
word6
我想Directory.twml说的样子是
11:38:38.90 [System] Twml Has joined the chat.
11:38:41.17 [User] Twml says: line one
11:38:42.96 [User] Twml says: line [Blocked] two
11:38:46.27 [User] Twml says: line three
11:38:50.16 [User] Twml says: you get the idea here
11:38:52.35 [System] Twml Has logged off.
我已经可以使用Findstr工具来查找该文件中,看看文中涉及但多数民众赞成至于我能,我需要不检查一组字,但检查该文件中的单词列表Blocked.twml
findstr /i "bad" <"Directory.twml" 1>nul
而且我可以从文件中删除这个词,但我想取代它不只是删除
findstr /i /v /c:"%text%" Directory.twml > "Directory.twmll" 2>nul
del Directory.twml /s /a >nul
copy Directory.twmll Directory.twml >nul
attrib +h Directory.twml
del Directory.twmll /s /a >nul
,但这又是一个集合文本寻找不从什么是在一个文件列表
如果Directory.twml包含Blocked.twml任何替换[锁定]但我无法弄清楚如何做到这一点
===== ====编辑===========
这是解决方案:
(
for /f "delims=" %%A in (Directory.twml) do (
set "line=%%A"
for /f "delims=" %%B in (blocked.twml) do set "line=!line: %%B = [Blocked] !"
echo !line!
)
)>Directory.new
它的输出看起来像这样对我
13:22:14.16 [User] twml says: this is a test
13:22:20.37 [User] twml says: this is a [Blocked] word test
请不要回答问题(然后它在技术上没有问题了)。 [阅读此](https://stackoverflow.com/help/someone-answers) – Stephan
这不是一个教学评论它是一个请求;请接受@ Stephan的回答,因为你的帖子清楚地表明你有! – Compo