我需要使用批處理來檢查文件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