Search and replace text in a txt file by a batch file in Windows

喜欢而已 提交于 2020-01-17 07:56:19

问题


I have a huge file approx 100 mb to 500 mb, it take more time to open it and I cannot change it also due to slow response in Notepad or notepad++.

I have requirement to replace only REF Number and this is only one time in the file.

Can I have a Batch file/ Script in Command prompt so that I can replace the text?

Regards and Thx.


回答1:


@echo off
set "toreplace=REF"
for /f "tokens=* delims= " %%a in (yourfile.txt) do (
set "line=%%a"
setlocal enabledelayedexpansion
set "line=!line:%toreplace%=!"
echo !line! >>newfile.txt
)

this code deletes all REF strings from yourfile.txt and outputs it to newfile.txt.
not my code.



来源:https://stackoverflow.com/questions/42052039/search-and-replace-text-in-a-txt-file-by-a-batch-file-in-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!