在Windows中用批处理文件搜索并替换txt文件中的文本 [英] Search and replace text in a txt file by a batch file in Windows

查看:532
本文介绍了在Windows中用批处理文件搜索并替换txt文件中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大约100 mb至500 mb的大文件,打开它需要更多时间,而且由于记事本或notepad ++的响应缓慢,我也无法更改它.

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++.

我只需要替换REF号,而这仅是文件中的一次.

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?

问候和感激之情.

推荐答案

@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
)

此代码从yourfile.txt删除所有REF字符串,并将其输出到newfile.txt.
不是我的代码.

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

这篇关于在Windows中用批处理文件搜索并替换txt文件中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆